linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] Move all btrfs command to only one command
@ 2010-01-21 19:29 Goffredo Baroncelli
  2010-01-22  0:02 ` TARUISI Hiroaki
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-01-21 19:29 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Nicol, taruishi.hiroak

[-- Attachment #1: Type: text/plain, Size: 4091 bytes --]

Hi all

this RFC is about unify all btrfs command (btrfsctl, btrfs-show, btrfs-tune.. 
) in only one called "btrfs" (or whatever we want).

Today "btrfsctl" needs a "bit" of care because
  * the help is basically wrong [1]
  * the return codes are incoherent [2]
  * the syntax of the command are very ugly (a lot of people complained 
    about the subvolumes/snapshot creation, because they aren't very clear)
    [3]
  * the code is a mess (in the main there is a useless for(); there a lot
    of 'if' because sometime the last argument is the target of ioctl,
    sometime no..) [4]
  * The checks of the number of argument are incorrect [5]

I think that is better to rewrite from scratch a new command instead of 
patching the old one. So we don't care about the backward compatibility.

Other filesystem (hammer, tux3, zfs) have only one command for management 
purpose. Instead we have btrfsctl (which has a lot of different
function) and btrfs-show, btrfs-tune, btrfs-volume which have few functions.

There are patches which address [6] some of the previous issues, 
but these are not integrated (because the developers are busy on other 
issues). To me rewriting from scratch seems a fast path for solving these 
issues.

I made a prototype (see attached file) in bash of what "btrfs" should be. The 
major different from btrfsctl are:
- I talk about clone and not snapshot
- If a sub-volume is required (for example for the cloning), the program check 
that the argument is a root of the subvolume and not a subdirectory
- Creating a sub-volume requires only one argument 

Below some examples:

$ btrfs                         
Usage:                                              
        btrfs clone|-c <source> [<dest>/]<name>     
                Clone the subvolume <source> with the name <name> in the 
<dest>
                directory.                                                     
        btrfs delete|-d <subvolume>                                            
                Delete the subvolume <subvolume>.                              
        btrfs create|-C [<dest>/]<name>
                Create a subvolume in <dest> (or the current directory if not
                passed.
        btrfs defrag|-d <file>|<dir> [<file>|<dir>...]
                Defragment a file or a directory.
        btrfs fssync|-s <path>
                Force a fs sync on the filesystem <path>
        btrfs resize|-r [+/-]<newsize>[gkm]|max <filesystem>
                Resize the file system. If 'max' is passed, the filesystem
                will occupe all available space on the device.
        btrfs scan|-S [<device> [<device>..]
                Scan all device for or the passed device for a btrfs 
filesystem.
        btrfs show|-l <dev>|<label> [<dev>|<label>.. ]
                Show the btrfs devices
        btrfs balance|-b <path>
                Balance teh chunk across the device
        btrfs add|-A <dev> <path>
                Add a device to a filesystem
        btrfs rem|-R <dev> <path>
                Remove a device to a filesystem

        btrfs help|--help|-h
                Show the help.



Comment are welcome




[1] In the help the -r, -c options seem that don't need any further argument; 
The -D command seems that accpet only "." as 2nd parameter....

[2] If something goes wrong btrfsctl returns 1; if the ioctl return 0 the 
command still returns 1...

[3] See the email in the mailing list

[4] If I does
   btrfsctl -c -d -A -S a .
what result do you aspect ?

[5] If I pass more argument than the ones needed no error is showed. -D checks 
if there is only one argument, when it needs two argument...

[6] 
- 10/26/09 - little fixme in btrfsctl.c [PATCH] - From: 
David Nicol <davidnicol@gmail.com>
- 12/24/09 - [PATCH] btrfs-progs: check slash in deleting subvolumes. - From: 
TARUISI 
- 12/13/09 - [PATCH] Improve the btrfsctl help - From: 
Goffredo Baroncelli <kreijack@gmail.com>


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijackATinwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

[-- Attachment #2: btrfs --]
[-- Type: application/x-shellscript, Size: 6413 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-01-21 19:29 [RFC] Move all btrfs command to only one command Goffredo Baroncelli
@ 2010-01-22  0:02 ` TARUISI Hiroaki
  2010-01-22  0:11 ` Michael Niederle
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 26+ messages in thread
From: TARUISI Hiroaki @ 2010-01-22  0:02 UTC (permalink / raw)
  To: kreijack; +Cc: linux-btrfs, davidnicol, chris.mason

Hi Goffredo,

It sounds good for me though detailed points need more discussion.
btrfs-progs seems unkind for operator as you mentioned, and many
features will be implemented to btrfsctl from now, it's good that
we arrange and unify btrfs-progs now.

As for me, plain keywords(delete,defrag...) as commands are welcome.

Regards,
taruisi

(2010/01/22 4:29), Goffredo Baroncelli wrote:
> Hi all
> 
> this RFC is about unify all btrfs command (btrfsctl, btrfs-show, btrfs-tune.. 
> ) in only one called "btrfs" (or whatever we want).
> 
> Today "btrfsctl" needs a "bit" of care because
>   * the help is basically wrong [1]
>   * the return codes are incoherent [2]
>   * the syntax of the command are very ugly (a lot of people complained 
>     about the subvolumes/snapshot creation, because they aren't very clear)
>     [3]
>   * the code is a mess (in the main there is a useless for(); there a lot
>     of 'if' because sometime the last argument is the target of ioctl,
>     sometime no..) [4]
>   * The checks of the number of argument are incorrect [5]
> 
> I think that is better to rewrite from scratch a new command instead of 
> patching the old one. So we don't care about the backward compatibility.
> 
> Other filesystem (hammer, tux3, zfs) have only one command for management 
> purpose. Instead we have btrfsctl (which has a lot of different
> function) and btrfs-show, btrfs-tune, btrfs-volume which have few functions.
> 
> There are patches which address [6] some of the previous issues, 
> but these are not integrated (because the developers are busy on other 
> issues). To me rewriting from scratch seems a fast path for solving these 
> issues.
> 
> I made a prototype (see attached file) in bash of what "btrfs" should be. The 
> major different from btrfsctl are:
> - I talk about clone and not snapshot
> - If a sub-volume is required (for example for the cloning), the program check 
> that the argument is a root of the subvolume and not a subdirectory
> - Creating a sub-volume requires only one argument 
> 
> Below some examples:
> 
> $ btrfs                         
> Usage:                                              
>         btrfs clone|-c <source> [<dest>/]<name>     
>                 Clone the subvolume <source> with the name <name> in the 
> <dest>
>                 directory.                                                     
>         btrfs delete|-d <subvolume>                                            
>                 Delete the subvolume <subvolume>.                              
>         btrfs create|-C [<dest>/]<name>
>                 Create a subvolume in <dest> (or the current directory if not
>                 passed.
>         btrfs defrag|-d <file>|<dir> [<file>|<dir>...]
>                 Defragment a file or a directory.
>         btrfs fssync|-s <path>
>                 Force a fs sync on the filesystem <path>
>         btrfs resize|-r [+/-]<newsize>[gkm]|max <filesystem>
>                 Resize the file system. If 'max' is passed, the filesystem
>                 will occupe all available space on the device.
>         btrfs scan|-S [<device> [<device>..]
>                 Scan all device for or the passed device for a btrfs 
> filesystem.
>         btrfs show|-l <dev>|<label> [<dev>|<label>.. ]
>                 Show the btrfs devices
>         btrfs balance|-b <path>
>                 Balance teh chunk across the device
>         btrfs add|-A <dev> <path>
>                 Add a device to a filesystem
>         btrfs rem|-R <dev> <path>
>                 Remove a device to a filesystem
> 
>         btrfs help|--help|-h
>                 Show the help.
> 
> 
> 
> Comment are welcome
> 
> 
> 
> 
> [1] In the help the -r, -c options seem that don't need any further argument; 
> The -D command seems that accpet only "." as 2nd parameter....
> 
> [2] If something goes wrong btrfsctl returns 1; if the ioctl return 0 the 
> command still returns 1...
> 
> [3] See the email in the mailing list
> 
> [4] If I does
>    btrfsctl -c -d -A -S a .
> what result do you aspect ?
> 
> [5] If I pass more argument than the ones needed no error is showed. -D checks 
> if there is only one argument, when it needs two argument...
> 
> [6] 
> - 10/26/09 - little fixme in btrfsctl.c [PATCH] - From: 
> David Nicol <davidnicol@gmail.com>
> - 12/24/09 - [PATCH] btrfs-progs: check slash in deleting subvolumes. - From: 
> TARUISI 
> - 12/13/09 - [PATCH] Improve the btrfsctl help - From: 
> Goffredo Baroncelli <kreijack@gmail.com>
> 
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-01-21 19:29 [RFC] Move all btrfs command to only one command Goffredo Baroncelli
  2010-01-22  0:02 ` TARUISI Hiroaki
@ 2010-01-22  0:11 ` Michael Niederle
  2010-01-22  9:33   ` Xavier Nicollet
  2010-01-22  8:23 ` Adrian von Bidder
  2010-01-24 17:35 ` [RFC] Move all btrfs command to only one command: btrfs.c Goffredo Baroncelli
  3 siblings, 1 reply; 26+ messages in thread
From: Michael Niederle @ 2010-01-22  0:11 UTC (permalink / raw)
  To: Goffredo Baroncelli; +Cc: linux-btrfs, David Nicol, taruishi.hiroak

> $ btrfs                         
> Usage:                                              
>         btrfs clone|-c <source> [<dest>/]<name>     
>                 Clone the subvolume <source> with the name <name> in the 
> <dest>
>                 directory.                                                     
>         btrfs delete|-d
> <subvolume> Delete the subvolume <subvolume>.                              
>         btrfs create|-C [<dest>/]<name>
>                 Create a subvolume in <dest> (or the current directory if not
>                 passed.
>         btrfs defrag|-d <file>|<dir> [<file>|<dir>...]
>                 Defragment a file or a directory.
>         btrfs fssync|-s <path>
>                 Force a fs sync on the filesystem <path>
>         btrfs resize|-r [+/-]<newsize>[gkm]|max <filesystem>
>                 Resize the file system. If 'max' is passed, the filesystem
>                 will occupe all available space on the device.
>         btrfs scan|-S [<device> [<device>..]
>                 Scan all device for or the passed device for a btrfs 
> filesystem.
>         btrfs show|-l <dev>|<label> [<dev>|<label>.. ]
>                 Show the btrfs devices
>         btrfs balance|-b <path>
>                 Balance teh chunk across the device
>         btrfs add|-A <dev> <path>
>                 Add a device to a filesystem
>         btrfs rem|-R <dev> <path>
>                 Remove a device to a filesystem
> 
>         btrfs help|--help|-h
>                 Show the help.

I like this idea!

Just a small suggestion:

"btrfs remove" instead of "btrfs rem"

-----

Another question: Is there a simple way to convert a directory into a subvolume?

Currently I first create the new subvolume; copy or move the data of the
directory into the new subvolume, then delete the directory and finally
rename the subvolume.

Greetings, Michael

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-01-21 19:29 [RFC] Move all btrfs command to only one command Goffredo Baroncelli
  2010-01-22  0:02 ` TARUISI Hiroaki
  2010-01-22  0:11 ` Michael Niederle
@ 2010-01-22  8:23 ` Adrian von Bidder
  2010-01-24 17:35 ` [RFC] Move all btrfs command to only one command: btrfs.c Goffredo Baroncelli
  3 siblings, 0 replies; 26+ messages in thread
From: Adrian von Bidder @ 2010-01-22  8:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Goffredo Baroncelli

[-- Attachment #1: Type: Text/Plain, Size: 924 bytes --]

Hi,

I like this very much, I found myself wondering which program did what again 
and again when I started to use btrfs, too.

On Thursday 21 January 2010 20.29:26 Goffredo Baroncelli wrote:
>        btrfs resize|-r [+/-]<newsize>[gkm]|max <filesystem>
>                Resize the file system. If 'max' is passed, the filesystem
>                will occupe all available space on the device.

Switch the arguments, and if the 2nd is missing do what you propose for 
"max".

>         btrfs scan|-S [<device> [<device>..]
>                 Scan all device for or the passed device for a btrfs
> filesystem.

This is the only that *migt* be sensible to have as a separate tool, if 
"btrfs" ends up requiring additional runtime dependencies: the scan utility 
should be small since it will need to be included in the initrd.

-- 
Protect your privacy - encrypt your email: http://fortytwo.ch/gpg/intro

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 389 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-01-22  0:11 ` Michael Niederle
@ 2010-01-22  9:33   ` Xavier Nicollet
  0 siblings, 0 replies; 26+ messages in thread
From: Xavier Nicollet @ 2010-01-22  9:33 UTC (permalink / raw)
  To: Michael Niederle
  Cc: Goffredo Baroncelli, linux-btrfs, David Nicol, taruishi.hiroak

Le 22 janvier 2010 =E0 01:11, Michael Niederle a =E9crit:
> >         btrfs clone|-c <source> [<dest>/]<name>    =20
> >                 Clone the subvolume <source> with the name <name> i=
n the=20
> > <dest>
> >                 directory.                                         =
           =20

Maybe you should add the "writable snapshot" in the description, since
everyone is using the word "snapshot" on the mailing list.
When I hear "clone", I understand "dump".

> >         btrfs delete|-d
> > <subvolume> Delete the subvolume <subvolume>.                      =
       =20

> >         btrfs rem|-R <dev> <path>
> >                 Remove a device to a filesystem

> Just a small suggestion:
> "btrfs remove" instead of "btrfs rem"

Why not "btrfs rm", which reminds "git rm" ?
Actually, I would do something like:

btrfs vol add
btrfs vol rm

btrfs dev add
btrfs dev rm=20

It would bet simpler, wouldn't it ?

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [RFC] Move all btrfs command to only one command: btrfs.c
  2010-01-21 19:29 [RFC] Move all btrfs command to only one command Goffredo Baroncelli
                   ` (2 preceding siblings ...)
  2010-01-22  8:23 ` Adrian von Bidder
@ 2010-01-24 17:35 ` Goffredo Baroncelli
  2010-01-24 18:34   ` Piavlo
  2010-02-11 16:33   ` Chris Mason
  3 siblings, 2 replies; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-01-24 17:35 UTC (permalink / raw)
  To: linux-btrfs
  Cc: taruishi.hiroak, Michael Niederle, Xavier Nicollet, Adrian von Bidder

[-- Attachment #1: Type: Text/Plain, Size: 20275 bytes --]

Hi all,

this is a follow-up of the previous email. I rewrite the btrfs command in C. 
Now the following actions are implemented:

snapshot (-s) -> create a snapshot
delete   (-D) -> delete a subvolume or a snapshot
create   (-S) -> create a subvolume
defrag   (-d) -> defrag a tree or a file
fssync   (-c) -> sync a filesystem
scan     (-a) -> scan devices searching a btrfs filesystem
show     (-l) -> list the btrfs fs and its  volumes
balance  (-b) -> balance the chunk across the volumes
add-dev  (-A) -> add a volume to a filesystem
rem-dev  (-R) -> remove a volume to a filesystem

I cared that btrfs returns appropriate error code. And I check that a correct 
parameters number is passed. Finally, where appropriate if a subvolume is 
required (for example in case of snapshot and or delete) is checked that the 
passed path is a subvolume. This should limits the complain like:
- I snapshot a sub directory, but I got a snapshot of the entire tree.

I renamed remove (a volume) in rem-dev in order to avoid confusion with delete 
(a subvolume).

You can find a git repository in 

	http://cassiopea.homelinux.net/git/?p=btrfs-command.git;a=summary

select the branch "btrfs-command"

TODO:
* resizing implementation
* btrfstune implementation
* btrfslabel implementation (but it require patch to the kernel)
* mkfs implementation
* check of the label length
* test suite finalisation
* test, test, test

Suggestions are welcome.

BR
G.Baroncelli

diff --git a/Makefile b/Makefile
index 02f881e..888ef8d 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ bindir = $(prefix)/bin
 LIBS=-luuid
 
 progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \
-	btrfs-map-logical
+	btrfs-map-logical btrfs
 
 # make C=1 to enable sparse
 ifdef C
@@ -36,6 +36,9 @@ all: version $(progs) manpages
 version:
 	bash version.sh
 
+btrfs: $(objects) btrfs.o
+	gcc $(CFLAGS) -o btrfs btrfs.o $(objects) $(LDFLAGS) $(LIBS)
+
 btrfsctl: $(objects) btrfsctl.o
 	gcc $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS)
 
diff --git a/btrfs.c b/btrfs.c
new file mode 100644
index 0000000..369e556
--- /dev/null
+++ b/btrfs.c
@@ -0,0 +1,743 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <limits.h>
+#include <uuid/uuid.h>
+
+#undef ULONG_MAX
+
+#include "kerncompat.h"
+#include "ctree.h"
+#include "transaction.h"
+#include "utils.h"
+#include "version.h"
+#include "ioctl.h"
+#include "volumes.h"
+
+#ifdef __CHECKER__
+#define BLKGETSIZE64 0
+#define BTRFS_IOC_SNAP_CREATE 0
+#define BTRFS_VOL_NAME_MAX 255
+struct btrfs_ioctl_vol_args { char name[BTRFS_VOL_NAME_MAX]; };
+static inline int ioctl(int fd, int define, void *arg) { return 0; }
+#endif
+
+/*
+ * test if path is a subvolume: 
+ * this function return
+ * 0-> path exists but it is not a subvolume
+ * 1-> path exists and it is  a subvolume
+ * -1 -> path is unaccessible
+ */
+static int test_issubvolume(char *path)
+{
+
+	struct stat 	st;
+	int		res;
+
+	res = stat(path, &st);
+	if(res < 0 )
+		return -1;
+
+	return (st.st_ino == 256) && S_ISDIR(st.st_mode);
+	
+}
+
+/*
+ * test if path is a directory
+ * this function return
+ * 0-> path exists but it is not a directory
+ * 1-> path exists and it is  a directory
+ * -1 -> path is unaccessible
+ */
+static int test_isdir(char *path)
+{
+	struct stat 	st;
+	int		res;
+
+	res = stat(path, &st);
+	if(res < 0 )
+		return -1;
+
+	return S_ISDIR(st.st_mode);
+
+}
+
+static int open_file_or_dir(const char *fname)
+{
+	int ret;
+	struct stat st;
+	DIR *dirstream;
+	int fd;
+
+	ret = stat(fname, &st);
+	if (ret < 0) {
+		return -1;
+	}
+	if (S_ISDIR(st.st_mode)) {
+		dirstream = opendir(fname);
+		if (!dirstream) {
+			return -2;
+		}
+		fd = dirfd(dirstream);
+	} else {
+		fd = open(fname, O_RDWR);
+	}
+	if (fd < 0) {
+		return -3;
+	}
+	return fd;
+}
+
+static int do_clone(char *subvol, char *dst)
+{
+	int	res, fd, fddst;
+	char	*newname;
+	char	*dstdir;
+	struct btrfs_ioctl_vol_args	args;
+
+	res = test_issubvolume(subvol);
+	if(res<0){
+		fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
+		return 12;
+	}
+	if(!res){
+		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
+		return 13;
+	}
+
+	res = test_isdir(dst);
+	if(res == 0 ){
+		fprintf(stderr, "ERROR: '%s' exists and it is not a 
directory\n", dst);
+		return 12;
+	}
+
+	if(res>0){
+		newname = strdup(subvol);
+		newname = basename(newname);
+		dstdir = dst;
+	}else{
+		newname = strdup(dst);
+		newname = basename(newname);
+		dstdir = strdup(dst);
+		dstdir = dirname(dstdir);
+	}
+
+	if( !strcmp(newname,".") || !strcmp(newname,"..") ||
+	     strchr(newname, '/') ){
+		fprintf(stderr, "ERROR: uncorrect snapshot name ('%s')\n",
+			newname);
+		return 14;
+	}
+
+	fddst = open_file_or_dir(dstdir);
+	if (fddst < 0) {
+		fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
+		return 12;
+	}
+
+	fd = open_file_or_dir(subvol);
+	if (fd < 0) {
+		close(fddst);
+		fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
+		return 12;
+	}
+
+	printf("Create a snapshot of '%s' in '%s/%s'\n",
+	       subvol, dstdir, newname);
+	args.fd = fd;
+	strcpy(args.name, newname);
+	res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args);
+
+	close(fd);
+	close(fddst);
+
+	if(res < 0 ){
+		fprintf( stderr, "ERROR: cannot snapshot '%s'\n",subvol);
+		return 11;
+	}
+
+	return 0;
+
+}
+
+static int do_delete_subvolume(char *path)
+{
+	int	res, fd;
+	struct btrfs_ioctl_vol_args	args;
+	char	*dname, *vname, *cpath;
+	
+	res = test_issubvolume(path);
+	if(res<0){
+		fprintf(stderr, "ERROR: error accessing '%s'\n", path);
+		return 12;
+	}
+	if(!res){
+		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", path);
+		return 13;
+	}
+	
+	cpath = realpath(path, 0);
+	dname = strdup(cpath);
+	dname = dirname(dname);
+	vname = strdup(cpath);
+	vname = basename(vname);
+	free(cpath);
+	
+	if( !strcmp(vname,".") || !strcmp(vname,"..") ||
+	     strchr(vname, '/') ){
+		fprintf(stderr, "ERROR: uncorrect subvolume name ('%s')\n",
+			vname);
+		return 14;
+	}
+	
+	fd = open_file_or_dir(dname);
+	if (fd < 0) {
+		close(fd);
+		fprintf(stderr, "ERROR: can't access to '%s'\n", dname);
+		return 12;
+	}
+
+	printf("Delete subvolume '%s/%s'\n", dname, vname);
+	strcpy(args.name, vname);
+	res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
+
+	close(fd);
+
+	if(res < 0 ){
+		fprintf( stderr, "ERROR: cannot delete '%s/%s'\n",dname, 
vname);
+		return 11;
+	}
+
+	return 0;
+
+}
+
+static int do_create_subvol(char *dst)
+{
+	int	res, fddst;
+	char	*newname;
+	char	*dstdir;
+	struct btrfs_ioctl_vol_args	args;
+
+	res = test_isdir(dst);
+	if(res >= 0 ){
+		fprintf(stderr, "ERROR: '%s' exists\n", dst);
+		return 12;
+	}
+
+	newname = strdup(dst);
+	newname = basename(newname);
+	dstdir = strdup(dst);
+	dstdir = dirname(dstdir);
+
+	if( !strcmp(newname,".") || !strcmp(newname,"..") ||
+	     strchr(newname, '/') ){
+		fprintf(stderr, "ERROR: uncorrect subvolume name ('%s')\n",
+			newname);
+		return 14;
+	}
+
+	fddst = open_file_or_dir(dstdir);
+	if (fddst < 0) {
+		fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
+		return 12;
+	}
+
+	printf("Create subvolume '%s/%s'\n", dstdir, newname);
+	strcpy(args.name, newname);
+	res = ioctl(fddst, BTRFS_IOC_SUBVOL_CREATE, &args);
+
+	close(fddst);
+
+	if(res < 0 ){
+		fprintf( stderr, "ERROR: cannot create subvolume\n");
+		return 11;
+	}
+
+	return 0;
+
+}
+
+static int do_fssync(char *path)
+{
+	int fd, res;
+	
+	fd = open_file_or_dir(path);
+	if (fd < 0) {
+		fprintf(stderr, "ERROR: can't access to '%s'\n", path);
+		return 12;
+	}
+
+	printf("FSSync '%s'\n", path);
+	res = ioctl(fd, BTRFS_IOC_SYNC);
+	close(fd);
+	if( res < 0 ){
+		fprintf(stderr, "ERROR: unable to fs-syncing '%s'\n", path);
+		return 16;
+	}
+
+	return 0;
+}
+
+static int do_scan(int nargs, char **argv)
+{
+	int	i, fd;
+	if(!nargs){
+		int ret;
+		
+		printf("Scanning for Btrfs filesystems\n");
+		ret = btrfs_scan_one_dir("/dev", 1);
+		if (ret){
+			fprintf(stderr, "ERROR: error %d while scanning\n", 
ret);
+			return 18;
+		}
+		return 0;
+	}
+
+	fd = open("/dev/btrfs-control", O_RDWR);
+	if (fd < 0) {
+		perror("failed to open /dev/btrfs-control");
+		return 10;
+	}
+
+	for( i = 0 ; i < nargs ; i++ ){
+		struct btrfs_ioctl_vol_args 	args;
+		int	ret;
+
+		printf("Scanning for Btrfs filesystems in '%s'\n", argv[i]);
+		
+		strcpy(args.name, argv[i]);
+		/*
+		 * FIXME: which are the error code returned by this ioctl ?
+		 * it seems that is impossible to undetand if there no is
+		 * a btrfs filesystem from an I/O error !!!
+		 */
+		ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
+
+		if( ret < 0 ){
+			close(fd);
+			fprintf(stderr, "ERROR: unable to scan the device 
'%s'\n", argv[i]);
+			return 11;
+		}
+	}
+
+	close(fd);
+	return 0;
+		
+}
+
+static int do_defrag(int argc, char **argv)
+{
+
+	int	i, ret=0;
+	
+	for(i=0 ; i <argc ; i++){
+		int	fd, res;
+		char	*path = argv[i];
+		fd = open_file_or_dir(path);
+		if (fd < 0) {
+			fprintf(stderr, "ERROR: can't access to '%s'\n", 
path);
+			ret++;
+			continue;
+		}
+
+		printf("Defrag '%s'\n", path);
+		res = ioctl(fd, BTRFS_IOC_DEFRAG);
+		close(fd);
+		if( res < 0 ){
+			fprintf(stderr, "ERROR: unable to defrag '%s'\n", 
argv[i]);
+			ret++;
+			continue;
+		}
+	}
+
+	/*
+	 * the return code is 0 (success) or the number of the failure + 20
+	 */
+	if(ret)
+		ret+=20;
+	return ret;
+}
+
+static int uuid_search(struct btrfs_fs_devices *fs_devices, char *search)
+{
+	struct list_head *cur;
+	struct btrfs_device *device;
+
+	list_for_each(cur, &fs_devices->devices) {
+		device = list_entry(cur, struct btrfs_device, dev_list);
+		if ((device->label && strcmp(device->label, search) == 0) ||
+		    strcmp(device->name, search) == 0)
+			return 1;
+	}
+	return 0;
+}
+
+static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
+{
+	char uuidbuf[37];
+	struct list_head *cur;
+	struct btrfs_device *device;
+	char *super_bytes_used;
+	u64 devs_found = 0;
+	u64 total;
+
+	uuid_unparse(fs_devices->fsid, uuidbuf);
+	device = list_entry(fs_devices->devices.next, struct btrfs_device,
+			    dev_list);
+	if (device->label && device->label[0])
+		printf("Label: '%s' ", device->label);
+	else
+		printf("Label: none ");
+
+	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,
+	       (unsigned long long)total, super_bytes_used);
+
+	free(super_bytes_used);
+
+	list_for_each(cur, &fs_devices->devices) {
+		char *total_bytes;
+		char *bytes_used;
+		device = list_entry(cur, struct btrfs_device, dev_list);
+		total_bytes = pretty_sizes(device->total_bytes);
+		bytes_used = pretty_sizes(device->bytes_used);
+		printf("\tdevid %4llu size %s used %s path %s\n",
+		       (unsigned long long)device->devid,
+		       total_bytes, bytes_used, device->name);
+		free(total_bytes);
+		free(bytes_used);
+		devs_found++;
+	}
+	if (devs_found < total) {
+		printf("\t*** Some devices missing\n");
+	}
+	printf("\n");
+}
+
+static int do_show_volume(char *search)
+{
+	struct list_head *all_uuids;
+	struct btrfs_fs_devices *fs_devices;
+	struct list_head *cur_uuid;
+	int ret;
+
+	ret = btrfs_scan_one_dir("/dev", 0);
+	if (ret){
+		fprintf(stderr, "ERROR: error %d while scanning\n", ret);
+		return 18;
+	}
+
+	all_uuids = btrfs_scanned_uuids();
+	list_for_each(cur_uuid, all_uuids) {
+		fs_devices = list_entry(cur_uuid, struct btrfs_fs_devices,
+					list);
+		if (search && uuid_search(fs_devices, search) == 0)
+			continue;
+		print_one_uuid(fs_devices);
+	}
+	printf("%s\n", BTRFS_BUILD_VERSION);
+	return 0;
+}
+
+static int do_add_volume(int nargs, char **args)
+{
+
+	char	*mntpnt = args[nargs-1];
+	int	i, fdmnt, ret=0;
+
+
+	fdmnt = open_file_or_dir(mntpnt);
+	if (fdmnt < 0) {
+		fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt);
+		return 12;
+	}	
+	
+	for(i=0 ; i < (nargs-1) ; i++ ){
+		struct 	btrfs_ioctl_vol_args ioctl_args;
+		int	devfd, res;
+		u64 dev_block_count = 0;
+		struct stat st;
+
+		devfd = open(args[i], O_RDWR);
+		if (!devfd) {
+			fprintf(stderr, "ERROR: Unable to open device '%s'\n", 
args[i]);
+			close(devfd);
+			ret++;
+			continue;
+		}
+		ret = fstat(devfd, &st);
+		if (ret) {
+			fprintf(stderr, "ERROR: Unable to stat '%s'\n", 
args[i]);
+			close(devfd);
+			ret++;
+			continue;
+		}
+		if (!S_ISBLK(st.st_mode)) {
+			fprintf(stderr, "ERROR: '%s' is not a block device\n", 
args[i]);
+			close(devfd);
+			ret++;
+			continue;
+		}		
+
+		res = btrfs_prepare_device(devfd, args[i], 1, 
&dev_block_count);
+		if (ret) {
+			fprintf(stderr, "ERROR: Unable to init '%s'\n", 
args[i]);
+			close(devfd);
+			ret++;
+			continue;
+		}
+		close(devfd);
+		
+		strcpy(ioctl_args.name, args[i]);
+		res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
+		if(res<0){
+			fprintf(stderr, "ERROR: error adding the device 
'%s'\n", args[i]);
+			ret++;
+		}
+
+	}
+
+	close(fdmnt);
+	if( ret)
+		return ret+20;
+	else
+		return 0;
+
+}
+
+static int do_balance(char *path)
+{
+
+	int	fdmnt, ret=0;
+
+	fdmnt = open_file_or_dir(path);
+	if (fdmnt < 0) {
+		fprintf(stderr, "ERROR: can't access to '%s'\n", path);
+		return 12;
+	}
+	
+	ret = ioctl(fdmnt, BTRFS_IOC_BALANCE);
+	close(fdmnt);
+	if(ret<0){
+		fprintf(stderr, "ERROR: balancing '%s'\n", path);
+		
+		return 19;
+	}
+	return 0;
+}
+static int do_remove_volume(int nargs, char **args)
+{
+
+	char	*mntpnt = args[nargs-1];
+	int	i, fdmnt, ret=0;
+
+	fdmnt = open_file_or_dir(mntpnt);
+	if (fdmnt < 0) {
+		fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt);
+		return 12;
+	}
+
+	for(i=0 ; i < (nargs-1) ; i++ ){
+		struct 	btrfs_ioctl_vol_args arg;
+		int	res;
+
+		strcpy(arg.name, args[i]);
+		res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
+		if(res<0){
+			fprintf(stderr, "ERROR: error removing the device 
'%s'\n", args[i]);
+			ret++;
+		}
+	}
+
+	close(fdmnt);
+	if( ret)
+		return ret+20;
+	else
+		return 0;
+}
+
+
+static void help(char *programname)
+{
+	char *np;
+
+	np = strrchr(programname,'/');
+	if(!np)
+		np = programname;
+	else
+		np++;
+	
+	printf("Usage:\n");
+	printf("	%s snapshot|-s <source> [<dest>/]<name>\n", np);
+	printf("		Create a writeble snapshot of the 
subvolume\n");
+	printf("		<source> with the name <name> in the 
<dest>\n");
+	printf("		directory.\n");
+	printf("	%s delete|-D <subvolume>\n", np);
+	printf("		Delete the subvolume <subvolume>.\n");
+	printf("	%s create|-S [<dest>/]<name>\n", np);
+	printf("		Create a subvolume in <dest> (or the current 
directory if not\n");
+	printf("		passed.\n");
+	printf("	%s defrag|-d <file>|<dir> [<file>|<dir>...]\n", np);
+	printf("		Defragment a file or a directory.\n");
+	printf("	%s fssync|-c <path>\n", np);
+	printf("		Force a fs sync on the filesystem <path>\n");
+	printf("	%s resize|-r [+/-]<newsize>[gkm]|max <filesystem>\n", 
np);
+	printf("		Resize the file system. If 'max' is passed, 
the filesystem\n");
+	printf("		will occupe all available space on the device.
\n");
+	printf("	%s scan|-a [<device> [<device>..]\n", np);
+	printf("		Scan all device for or the passed device for 
a\n");
+	printf("		btrfs filesystem.\n");
+	printf("	%s show|-l <dev>|<label> [<dev>|<label>...]\n", np);
+	printf("		Show the btrfs devices\n");
+	printf("	%s balance|-b <path>\n", np);
+	printf("		Balance the chunk across the device\n");
+	printf("	%s add-dev|-A <dev> [<dev>..] <path>\n", np);
+	printf("		Add a device to a filesystem\n");
+	printf("	%s rem-dev|-R <dev> [<dev>..] <path>\n", np);
+	printf("		Remove a device to a filesystem\n");
+	printf("\n");
+	printf("	%s help|--help|-h\n",np);
+	printf("		Show the help.\n");
+	printf("%s\n", BTRFS_BUILD_VERSION);
+
+}
+
+int main(int argc, char **argv )
+{
+
+	int	i;
+
+	for( i = 1 ; i < argc ; i++ ){
+		/* number of arguments after the verb*/
+		int	nargs = argc -i - 1;
+		
+		if( !strcmp(argv[i], "scan") || !strcmp(argv[i],"-a" )){
+			
+			exit(do_scan(nargs, argv+i+1));
+			
+		}else if( !strcmp(argv[i], "defrag") || !strcmp(argv[i],"-d" 
)){
+			if( nargs < 1 ){
+				fprintf(stderr,
+				  "ERROR: '%s' requires minimum 1 arg\n", 
argv[i]);
+				exit(2);
+			}
+			exit(do_defrag(nargs, argv+i+1));
+
+		}else if( !strcmp(argv[i], "snapshot") || !strcmp(argv[i],"-s" 
)){
+			
+			if( nargs > 2 || nargs < 2 ){
+				fprintf(stderr, "ERROR: '%s' requires 2 
args\n", argv[i]);
+				exit(2);
+			}
+			exit(do_clone(argv[i+1], argv[i+2]));
+
+		}else if( !strcmp(argv[i], "create") || !strcmp(argv[i],"-S" 
)){
+
+			if( nargs > 1 || nargs < 1 ){
+				fprintf(stderr, "ERROR: '%s' requires 1 
arg\n", argv[i]);
+				exit(2);
+			}
+			exit(do_create_subvol(argv[i+1]));
+
+		}else if( !strcmp(argv[i], "fssync") || !strcmp(argv[i],"-c" 
)){
+
+			if( nargs > 1 || nargs < 1 ){
+				fprintf(stderr, "ERROR: '%s' requires 1 
arg\n", argv[i]);
+				exit(2);
+			}
+			exit(do_fssync(argv[i+1]));
+
+		}else if( !strcmp(argv[i], "delete") || !strcmp(argv[i],"-D" 
)){
+
+			if( nargs > 1 || nargs < 1 ){
+				fprintf(stderr,
+				  "ERROR: '%s' requires 1 arg\n", argv[i]);
+				exit(2);
+			}
+			exit(do_delete_subvolume(argv[i+1]));
+
+		}else if( !strcmp(argv[i], "show") || !strcmp(argv[i],"-l" )){
+
+			if( nargs > 1 ){
+				fprintf(stderr,
+				  "ERROR: '%s' requires maximum 1 arg\n", 
argv[i]);
+				exit(2);
+			}
+			exit(do_show_volume(nargs ? argv[i+1]:0));
+			
+		}else if( !strcmp(argv[i], "add-dev") || !strcmp(argv[i],"-A" 
)){
+
+			if( nargs < 2 ){
+				fprintf(stderr,
+				  "ERROR: '%s' requires minimum 2 arg\n", 
argv[i]);
+				exit(2);
+			}
+			exit(do_add_volume(nargs, argv+i+1));
+
+		}else if( !strcmp(argv[i], "rem-dev") || !strcmp(argv[i],"-R" 
)){
+
+			if( nargs < 2 ){
+				fprintf(stderr,
+				  "ERROR: '%s' requires minimum 2 arg\n", 
argv[i]);
+				exit(2);
+			}
+			exit(do_remove_volume(nargs, argv+i+1));
+
+		}else if( !strcmp(argv[i], "balance") || !strcmp(argv[i],"-b" 
)){
+
+			if( nargs > 1 ){
+				fprintf(stderr,
+				  "ERROR: '%s' requires 1 arg\n", argv[i]);
+				exit(2);
+			}
+			exit(do_balance(argv[i+1]));
+
+		} else if( !strcmp(argv[i], "help") || !strcmp(argv[i], "-h") 
||
+				!strcmp(argv[i], "--help")){
+			help(argv[0]);
+			exit(0);
+		} else {
+			fprintf( stderr, "ERROR: unknow command 
'%s'\n",argv[i]);
+			help(argv[0]);
+			exit(1);
+		}
+
+	}
+
+	/*
+	 * no command is passed
+	 */
+	fprintf(stderr, "ERROR:  no command passed\n");
+	help(argv[0]);
+	exit(1);
+
+
+}
\ No newline at end of file

-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijackATinwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command: btrfs.c
  2010-01-24 17:35 ` [RFC] Move all btrfs command to only one command: btrfs.c Goffredo Baroncelli
@ 2010-01-24 18:34   ` Piavlo
  2010-02-11 16:33   ` Chris Mason
  1 sibling, 0 replies; 26+ messages in thread
From: Piavlo @ 2010-01-24 18:34 UTC (permalink / raw)
  To: Goffredo Baroncelli; +Cc: linux-btrfs

Goffredo Baroncelli wrote:
> Hi all,
>
> this is a follow-up of the previous email. I rewrite the btrfs command in C. 
> Now the following actions are implemented:
>
> snapshot (-s) -> create a snapshot
> delete   (-D) -> delete a subvolume or a snapshot
> create   (-S) -> create a subvolume
> defrag   (-d) -> defrag a tree or a file
> fssync   (-c) -> sync a filesystem
> scan     (-a) -> scan devices searching a btrfs filesystem
> show     (-l) -> list the btrfs fs and its  volumes
> balance  (-b) -> balance the chunk across the volumes
> add-dev  (-A) -> add a volume to a filesystem
> rem-dev  (-R) -> remove a volume to a filesystem
>
> I cared that btrfs returns appropriate error code. And I check that a correct 
> parameters number is passed. Finally, where appropriate if a subvolume is 
> required (for example in case of snapshot and or delete) is checked that the 
> passed path is a subvolume. This should limits the complain like:
> - I snapshot a sub directory, but I got a snapshot of the entire tree.
>
> I renamed remove (a volume) in rem-dev in order to avoid confusion with delete 
> (a subvolume).
>   
To avoid such confusion IMHO it's logically better to have two commands
instead one for handling actions at volume level
and other command at file system level  - something like btrfs & btrpool
- like in other well known file system :)

Alex
> You can find a git repository in 
>
> 	http://cassiopea.homelinux.net/git/?p=btrfs-command.git;a=summary
>
> select the branch "btrfs-command"
>
> TODO:
> * resizing implementation
> * btrfstune implementation
> * btrfslabel implementation (but it require patch to the kernel)
> * mkfs implementation
> * check of the label length
> * test suite finalisation
> * test, test, test
>
> Suggestions are welcome.
>
> BR
> G.Baroncelli
>   


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command: btrfs.c
  2010-01-24 17:35 ` [RFC] Move all btrfs command to only one command: btrfs.c Goffredo Baroncelli
  2010-01-24 18:34   ` Piavlo
@ 2010-02-11 16:33   ` Chris Mason
  2010-02-11 18:15     ` Goffredo Baroncelli
  2010-02-11 21:20     ` rk
  1 sibling, 2 replies; 26+ messages in thread
From: Chris Mason @ 2010-02-11 16:33 UTC (permalink / raw)
  To: Goffredo Baroncelli
  Cc: linux-btrfs, taruishi.hiroak, Michael Niederle, Xavier Nicollet,
	Adrian von Bidder

On Sun, Jan 24, 2010 at 06:35:33PM +0100, Goffredo Baroncelli wrote:
> Hi all,
> 
> this is a follow-up of the previous email. I rewrite the btrfs command in C. 
> Now the following actions are implemented:
> 
> snapshot (-s) -> create a snapshot
> delete   (-D) -> delete a subvolume or a snapshot
> create   (-S) -> create a subvolume
> defrag   (-d) -> defrag a tree or a file
> fssync   (-c) -> sync a filesystem
> scan     (-a) -> scan devices searching a btrfs filesystem
> show     (-l) -> list the btrfs fs and its  volumes
> balance  (-b) -> balance the chunk across the volumes
> add-dev  (-A) -> add a volume to a filesystem
> rem-dev  (-R) -> remove a volume to a filesystem
> 
> I cared that btrfs returns appropriate error code. And I check that a correct 
> parameters number is passed. Finally, where appropriate if a subvolume is 
> required (for example in case of snapshot and or delete) is checked that the 
> passed path is a subvolume. This should limits the complain like:
> - I snapshot a sub directory, but I got a snapshot of the entire tree.
> 
> I renamed remove (a volume) in rem-dev in order to avoid confusion with delete 
> (a subvolume).

Sorry for the late reply, but I really like this mode and will work on
integrating it.  rem-dev should be rm-dev or remove-dev

-chris

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command: btrfs.c
  2010-02-11 16:33   ` Chris Mason
@ 2010-02-11 18:15     ` Goffredo Baroncelli
  2010-02-11 21:20     ` rk
  1 sibling, 0 replies; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-02-11 18:15 UTC (permalink / raw)
  To: Chris Mason, linux-btrfs
  Cc: taruishi.hiroak, Michael Niederle, Xavier Nicollet, Adrian von Bidder

On Thursday 11 February 2010, Chris Mason wrote:
> On Sun, Jan 24, 2010 at 06:35:33PM +0100, Goffredo Baroncelli wrote:
> > Hi all,
> > 
> > this is a follow-up of the previous email. I rewrite the btrfs command in 
C. 
> > Now the following actions are implemented:
> > 
> > snapshot (-s) -> create a snapshot
> > delete   (-D) -> delete a subvolume or a snapshot
> > create   (-S) -> create a subvolume
> > defrag   (-d) -> defrag a tree or a file
> > fssync   (-c) -> sync a filesystem
> > scan     (-a) -> scan devices searching a btrfs filesystem
> > show     (-l) -> list the btrfs fs and its  volumes
> > balance  (-b) -> balance the chunk across the volumes
> > add-dev  (-A) -> add a volume to a filesystem
> > rem-dev  (-R) -> remove a volume to a filesystem
> > 
> > I cared that btrfs returns appropriate error code. And I check that a 
correct 
> > parameters number is passed. Finally, where appropriate if a subvolume is 
> > required (for example in case of snapshot and or delete) is checked that 
the 
> > passed path is a subvolume. This should limits the complain like:
> > - I snapshot a sub directory, but I got a snapshot of the entire tree.
> > 
> > I renamed remove (a volume) in rem-dev in order to avoid confusion with 
delete 
> > (a subvolume).
> 
> Sorry for the late reply, but I really like this mode and will work on
> integrating it.  rem-dev should be rm-dev or remove-dev

For me is ok; I will update my patch this week end

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


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command: btrfs.c
  2010-02-11 16:33   ` Chris Mason
  2010-02-11 18:15     ` Goffredo Baroncelli
@ 2010-02-11 21:20     ` rk
  2010-02-11 21:29       ` Goffredo Baroncelli
  1 sibling, 1 reply; 26+ messages in thread
From: rk @ 2010-02-11 21:20 UTC (permalink / raw)
  To: linux-btrfs, Michael Niederle, Xavier Nicollet, Adrian von Bidder

.. it would be good to have some "mechanism" that will "prevent" people
mixing -d with -D

Chris Mason wrote:
> On Sun, Jan 24, 2010 at 06:35:33PM +0100, Goffredo Baroncelli wrote:
>   
>> Hi all,
>>
>> this is a follow-up of the previous email. I rewrite the btrfs command in C. 
>> Now the following actions are implemented:
>>
>> snapshot (-s) -> create a snapshot
>> delete   (-D) -> delete a subvolume or a snapshot
>> create   (-S) -> create a subvolume
>> defrag   (-d) -> defrag a tree or a file
>> fssync   (-c) -> sync a filesystem
>> scan     (-a) -> scan devices searching a btrfs filesystem
>> show     (-l) -> list the btrfs fs and its  volumes
>> balance  (-b) -> balance the chunk across the volumes
>> add-dev  (-A) -> add a volume to a filesystem
>> rem-dev  (-R) -> remove a volume to a filesystem
>>
>> I cared that btrfs returns appropriate error code. And I check that a correct 
>> parameters number is passed. Finally, where appropriate if a subvolume is 
>> required (for example in case of snapshot and or delete) is checked that the 
>> passed path is a subvolume. This should limits the complain like:
>> - I snapshot a sub directory, but I got a snapshot of the entire tree.
>>
>> I renamed remove (a volume) in rem-dev in order to avoid confusion with delete 
>> (a subvolume).
>>     
>
> Sorry for the late reply, but I really like this mode and will work on
> integrating it.  rem-dev should be rm-dev or remove-dev
>
> -chris
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>   


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command: btrfs.c
  2010-02-11 21:20     ` rk
@ 2010-02-11 21:29       ` Goffredo Baroncelli
  0 siblings, 0 replies; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-02-11 21:29 UTC (permalink / raw)
  To: linux-btrfs

On Thursday 11 February 2010, rk wrote:
> . it would be good to have some "mechanism" that will "prevent" people
> mixing -d with -D

btrfs checks that the path passed to -D command is referred to a subvolume.
If there is an agreement I am open to change the switch (-d) of the defrag 
command. 

BR
Goffredo

> Chris Mason wrote:
> > On Sun, Jan 24, 2010 at 06:35:33PM +0100, Goffredo Baroncelli wrote:
> >   
> >> Hi all,
> >>
> >> this is a follow-up of the previous email. I rewrite the btrfs command in 
C. 
> >> Now the following actions are implemented:
> >>
> >> snapshot (-s) -> create a snapshot
> >> delete   (-D) -> delete a subvolume or a snapshot
> >> create   (-S) -> create a subvolume
> >> defrag   (-d) -> defrag a tree or a file
> >> fssync   (-c) -> sync a filesystem
> >> scan     (-a) -> scan devices searching a btrfs filesystem
> >> show     (-l) -> list the btrfs fs and its  volumes
> >> balance  (-b) -> balance the chunk across the volumes
> >> add-dev  (-A) -> add a volume to a filesystem
> >> rem-dev  (-R) -> remove a volume to a filesystem
> >>
> >> I cared that btrfs returns appropriate error code. And I check that a 
correct 
> >> parameters number is passed. Finally, where appropriate if a subvolume is 
> >> required (for example in case of snapshot and or delete) is checked that 
the 
> >> passed path is a subvolume. This should limits the complain like:
> >> - I snapshot a sub directory, but I got a snapshot of the entire tree.
> >>
> >> I renamed remove (a volume) in rem-dev in order to avoid confusion with 
delete 
> >> (a subvolume).
> >>     
> >
> > Sorry for the late reply, but I really like this mode and will work on
> > integrating it.  rem-dev should be rm-dev or remove-dev
> >
> > -chris
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> > the body of a message to majordomo@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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijackATinwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
       [not found]                   ` <AANLkTi=VpZv26jntJ8mwmxtjnQ5LDOn_MSm6VtEhJ1CB@mail.gmail.com>
@ 2010-08-27  3:38                     ` James Smith
  0 siblings, 0 replies; 26+ messages in thread
From: James Smith @ 2010-08-27  3:38 UTC (permalink / raw)
  To: linux-btrfs, kreijack

[-- Attachment #1: Type: text/plain, Size: 4928 bytes --]

diff --git a/btrfs_cmds.c b/btrfs_cmds.c
index e112902..271ca89 100644
--- a/btrfs_cmds.c
+++ b/btrfs_cmds.c
@@ -497,7 +497,7 @@ static void print_one_uuid(struct btrfs_fs_devices
*fs_devices)
                devs_found++;
        }
        if (devs_found < total) {
-               printf("\t*** Some devices missing\n");
+               printf("\t L1: Some devices missing\n");
        }
        printf("\n");
 }


diff --git a/btrfs.c b/btrfs.c
index 4d263c4..b3a087e 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -134,12 +135,13 @@ static void help(char *np)
 {
        struct Command *cp;

-       printf("Usage:\n");
+       printf("VFS-2593-A %s\n", BTRFS_BUILD_VERSION);
+       printf("\nNo matter where you go, there you are.\n");
+       printf("\nUsage:\n");
        for( cp = commands; cp->verb; cp++ )
                print_help(np, cp);

-       printf("\n\t%s help|--help|-h\n\t\tShow the help.\n",np);
-       printf("\n%s\n", BTRFS_BUILD_VERSION);
+       printf("\n\t%s help|--help|-h\n\t\tShow help.\n",np);
 }



I don't like the look of using errno.h at this time, so attached is
the error code file extracted from the help file and an additional
patch for label support. There may be leftover typos especially in the
errorcode.txt file so it might be nice to have a read-over. Does
someone want to get on strings translation? :)


On 8/21/10, James Smith <smithjd15@gmail.com> wrote:
> excuse me, errno.h.
>
> On 8/21/10, James Smith <smithjd15@gmail.com> wrote:
>> Thanks.
>>
>> What about stderr.h?
>>
>> On 8/21/10, Goffredo Baroncelli <kreijack@gmail.com> wrote:
>>> On Saturday, 21 August, 2010, James Smith wrote:
>>> [...]
>>>> I'll look at a error.txt file (after finding convention) and also
>>>> update the man. In regards to shortening of dev/device -- is this
>>>> really neccessary? And what harm does this cause in the first place?
>>>> In device add-delete functionality.
>>>
>>> Make sense to rename <dev> in <device> for the "btrfs add/delete"
>>> commands
>>>
>>>
>>>>
>>>>
>>>> On 8/20/10, Josh Berry <des@condordes.net> wrote:
>>>> > On Fri, Aug 20, 2010 at 12:00, Andreas Philipp
>>>> > <philipp.andreas@gmail.com> wrote:
>>>> >>  On 20.08.2010 20:49, Josh Berry wrote:
>>>> >>>
>>>> >>> On Fri, Aug 20, 2010 at 11:34, Andreas Philipp
>>>> >>> <philipp.andreas@gmail.com>  wrote:
>>>> >>>>
>>>> >>>>  On 20.08.2010 20:27, Josh Berry wrote:
>>>> >>>>>
>>>> >>>>> On Fri, Aug 20, 2010 at 05:03, Goffredo
>>> Baroncelli<kreijack@gmail.com>
>>>> >>>>>  wrote:
>>>> >>>>>>
>>>> >>>>>> On Thursday, 19 August, 2010, James Smith wrote:
>>>> >>>>>>>
>>>> >>>>>>> This patch randomizes the error codes and also fixes up some
>>>> >>>>>>> typos
>>>> >>>>>>
>>>> >>>>>> including
>>>> >>>>>>>
>>>> >>>>>>> capitalization in the output.
>>>> >>>>>>>
>>>> >>>>>>> It would almost be nice to see a translation effort for the
>>>> >>>>>>> tool
>>>> >>>>>>> as
>>>> >>>>>>> well.
>>>> >>>>>
>>>> >>>>> [...]
>>>> >>>>>>
>>>> >>>>>> +                       fprintf(stderr, "ERR-A.11: in command
>>>> >>>>>> '");
>>>> >>>>>>
>>>> >>>>>> I am not against this kind of error codes, but I prefer
>>>> >>>>>>
>>>> >>>>>> +                       fprintf(stderr, "Error 'ERR-A.11' in
>>>> >>>>>> command
>>>> >>>>>> '");
>>>> >>>>>
>>>> >>>>> As a layman/end user, I disagree.  The former format is easier
>>>> >>>>> for
>>>> >>>>> shell scripts and the like to parse -- the error code can be
>>> extracted
>>>> >>>>> with a simple "cut -d: -f1".
>>>> >>>>
>>>> >>>> This makes no difference. A simple `cut -d " " -f1` would do the
>>>> >>>> job
>>> in
>>>> >>>> the
>>>> >>>> second case.
>>>> >>>
>>>> >>> I think you meant -f2, and that still leaves the quotes hanging
>>>> >>> around.  So you'd need to cut -d" " -f2 |tr -d "'" .  It's not a
>>>> >>> big
>>>> >>> deal either way, I just think the former is easier to work with.
>>>> >>
>>>> >> Sorry, of course -f2. But why not simply cut -d "'" -f 2?
>>>> >
>>>> > Oh right, good point. :)  Though as Goffredo said, using the error
>>>> > code is probably better anyway.
>>>> >
>>>> > -- Josh
>>>> > --
>>>> > To unsubscribe from this list: send the line "unsubscribe
>>>> > linux-btrfs"
>>>> > in
>>>> > the body of a message to majordomo@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 majordomo@vger.kernel.org
>>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>>
>>>
>>>
>>> --
>>> gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo)
>>> <kreijack@inwind.it>
>>> Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs"
>>> in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>
>>
>

[-- Attachment #2: errorcodes.txt --]
[-- Type: text/plain, Size: 2242 bytes --]

Error code listing for btrfs.

A) Clone btrfs disk
A1: Error accessing the inputted subvolume.
A2: The inputted subvolume is not recognized as a subvolume.
A3: Passed argument is not a directory.

B) Snapshot btrfs disk
B1: Incorrect snapshot name has been entered.
B2: Inputted name is past the allowed length.
B3: Cannot access a requested file.
B4: Cannot access requested file.
B5: Cannot snapshot disk.

C) Delete subvolume
C1: Error deleting the inputted subvolume.
C2: Cannot delete the marked file. (Is not a subvolume)
C3: Incorrect subvolume name.
C4: Inputted name is past the allowed length. (Max char: 255)
C5: Cannot access the subvolume for deletion.
C6: Cannot delete subvolume.

D) Create subvolume
D1: Inputted name already exists.
D2: Incorrect subvolume name has been enteredI) Add Volume to filesystem.
I1: Can't access mount point point for adding volume.
I2: Unable to open device for adding volume.
I3: Unable to stat..
D3: Inputted name is past the allowed length. (Max char: 255)
D4: Cannot access requested file.
D5: Cannot create subvolume.
D6: Cannot access for syncing.
D7: Unable to create sync.

E) Scan for btrfs filesystems on block device.
E1: Error scanning for btrfs filesystem.
E2: Failed to open dev node to initialize filesystem tool.
E3: Unable to scan the device.

F) Defragment
F1: Cannot access the device to complete a defragment.
F2: Unable to defragment inputted device.

G) Resize 
G1: Cannot access device node for resize completion.
G2: Size value too long to allow resize.
G3: Unable to resize btrfs partition. 

H) Scan filesystem
H1: Error while scanning.

I) Add Volume to filesystem.
I1: Can't access mount point point for adding volume.
I2: Unable to open device for adding volume.
I3: Unable to stat.
I4: Not a block device.
I5: Unable to init device for adding of volumes.
I6: Error adding the device for adding volumes.

J) Balancing filesystems.
J1: Cannot access requested files.
J2: Balancing inodes.

K) Remove Volume from filesystem.
K1: Cannot addess requested file for volume removal.
K2: Error removing the device.

L) Label
L1: Some devices missing.


===
A.11) Ambiguous argument
B.12) Unknown Command
C.13) Minimum arguments unsatisfied
D.14) Minimum arguments unsatisfied

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-21  4:51             ` James Smith
@ 2010-08-21  9:37               ` Goffredo Baroncelli
       [not found]                 ` <AANLkTikJd8bDU1Eq22u0+yQ8eBCUn3OXHoE5E7uy+SG=@mail.gmail.com>
  0 siblings, 1 reply; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-08-21  9:37 UTC (permalink / raw)
  To: linux-btrfs

On Saturday, 21 August, 2010, James Smith wrote:
[...]
> I'll look at a error.txt file (after finding convention) and also
> update the man. In regards to shortening of dev/device -- is this
> really neccessary? And what harm does this cause in the first place?
> In device add-delete functionality.

Make sense to rename <dev> in <device> for the "btrfs add/delete" commands


> 
> 
> On 8/20/10, Josh Berry <des@condordes.net> wrote:
> > On Fri, Aug 20, 2010 at 12:00, Andreas Philipp
> > <philipp.andreas@gmail.com> wrote:
> >>  On 20.08.2010 20:49, Josh Berry wrote:
> >>>
> >>> On Fri, Aug 20, 2010 at 11:34, Andreas Philipp
> >>> <philipp.andreas@gmail.com>  wrote:
> >>>>
> >>>>  On 20.08.2010 20:27, Josh Berry wrote:
> >>>>>
> >>>>> On Fri, Aug 20, 2010 at 05:03, Goffredo 
Baroncelli<kreijack@gmail.com>
> >>>>>  wrote:
> >>>>>>
> >>>>>> On Thursday, 19 August, 2010, James Smith wrote:
> >>>>>>>
> >>>>>>> This patch randomizes the error codes and also fixes up some typos
> >>>>>>
> >>>>>> including
> >>>>>>>
> >>>>>>> capitalization in the output.
> >>>>>>>
> >>>>>>> It would almost be nice to see a translation effort for the tool as
> >>>>>>> well.
> >>>>>
> >>>>> [...]
> >>>>>>
> >>>>>> +                       fprintf(stderr, "ERR-A.11: in command '");
> >>>>>>
> >>>>>> I am not against this kind of error codes, but I prefer
> >>>>>>
> >>>>>> +                       fprintf(stderr, "Error 'ERR-A.11' in command
> >>>>>> '");
> >>>>>
> >>>>> As a layman/end user, I disagree.  The former format is easier for
> >>>>> shell scripts and the like to parse -- the error code can be 
extracted
> >>>>> with a simple "cut -d: -f1".
> >>>>
> >>>> This makes no difference. A simple `cut -d " " -f1` would do the job 
in
> >>>> the
> >>>> second case.
> >>>
> >>> I think you meant -f2, and that still leaves the quotes hanging
> >>> around.  So you'd need to cut -d" " -f2 |tr -d "'" .  It's not a big
> >>> deal either way, I just think the former is easier to work with.
> >>
> >> Sorry, of course -f2. But why not simply cut -d "'" -f 2?
> >
> > Oh right, good point. :)  Though as Goffredo said, using the error
> > code is probably better anyway.
> >
> > -- Josh
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> > the body of a message to majordomo@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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 20:28           ` Josh Berry
@ 2010-08-21  4:51             ` James Smith
  2010-08-21  9:37               ` Goffredo Baroncelli
  0 siblings, 1 reply; 26+ messages in thread
From: James Smith @ 2010-08-21  4:51 UTC (permalink / raw)
  To: Josh Berry; +Cc: Andreas Philipp, kreijack, linux-btrfs

Truthfully, this is probably this first I've actually done in C++; I
used to do PHP and a small amount of Javascript. I like that the tool
has seen some work and decided to at least attempt a bit more work
towards a decent tool.

Re: ERR codes. I don't know if a uniform approach is what's needed for
*nix usability. However should the codes end up unified to start with
or should there be some variety in how the single tool functions? I
don't know right now how much work it would be to roll fsck into it
and by that time the tool is done and the error codes would have to be
adjusted. The reason for the variety is simply from what I was able to
pull out of the style of coding vs. the function of the tool. Btrfsctl
wasn't really designed with a clean purpose in mind, i.e. the code
isn't as modular as could be expected for uniform functioning against
it's filesystem's role. The tools included by most filesystems in
Linux are already an afterthought with functional but poor
implementation. If reiserfs fell out of the sky as a model filesystem,
btrfsctl fell out of the sky as a model filesystem tool. I'd like to
keep the error-codes ambiguous to allow some expansion room for future
work. It's still an improvement over simply reporting 'error'.

Re: VFS-2593. I think it's a useless little change that probably
doesn't need to be there at all. As far as modelizing the tool
structure it might have some merit. Otherwise I don't know what isn't
feasible from a practicality standpoint as far as what other model
tools are included into the binary that relate to btrfs alone. How
long until Linux has a library for common filesystem operations, for
example? How does one differentiate the tools between filesystems? If
I were to choose a decent way to class tools I would probably break
the program to the point where it's functional and still has the
ability to exhibit new ideas; I don't know any other filesystem tool
that's had the same exposure on this side of the fence.

The poet in question actually ended up on a plaque for the Excelsior
starship of Star Trek fame, and I always kind of liked it. I sort of
don't see any reason to realistically retain it, though it might be
worth as a nonsensical psychological distraction to remember while a
filesystem is being tampered with. :)

I'll look at a error.txt file (after finding convention) and also
update the man. In regards to shortening of dev/device -- is this
really neccessary? And what harm does this cause in the first place?
In device add-delete functionality.


On 8/20/10, Josh Berry <des@condordes.net> wrote:
> On Fri, Aug 20, 2010 at 12:00, Andreas Philipp
> <philipp.andreas@gmail.com> wrote:
>>  On 20.08.2010 20:49, Josh Berry wrote:
>>>
>>> On Fri, Aug 20, 2010 at 11:34, Andreas Philipp
>>> <philipp.andreas@gmail.com>  wrote:
>>>>
>>>>  On 20.08.2010 20:27, Josh Berry wrote:
>>>>>
>>>>> On Fri, Aug 20, 2010 at 05:03, Goffredo Baroncelli<kreijack@gmail.com>
>>>>>  wrote:
>>>>>>
>>>>>> On Thursday, 19 August, 2010, James Smith wrote:
>>>>>>>
>>>>>>> This patch randomizes the error codes and also fixes up some typos
>>>>>>
>>>>>> including
>>>>>>>
>>>>>>> capitalization in the output.
>>>>>>>
>>>>>>> It would almost be nice to see a translation effort for the tool as
>>>>>>> well.
>>>>>
>>>>> [...]
>>>>>>
>>>>>> +                       fprintf(stderr, "ERR-A.11: in command '");
>>>>>>
>>>>>> I am not against this kind of error codes, but I prefer
>>>>>>
>>>>>> +                       fprintf(stderr, "Error 'ERR-A.11' in command
>>>>>> '");
>>>>>
>>>>> As a layman/end user, I disagree.  The former format is easier for
>>>>> shell scripts and the like to parse -- the error code can be extracted
>>>>> with a simple "cut -d: -f1".
>>>>
>>>> This makes no difference. A simple `cut -d " " -f1` would do the job in
>>>> the
>>>> second case.
>>>
>>> I think you meant -f2, and that still leaves the quotes hanging
>>> around.  So you'd need to cut -d" " -f2 |tr -d "'" .  It's not a big
>>> deal either way, I just think the former is easier to work with.
>>
>> Sorry, of course -f2. But why not simply cut -d "'" -f 2?
>
> Oh right, good point. :)  Though as Goffredo said, using the error
> code is probably better anyway.
>
> -- Josh
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 19:00         ` Andreas Philipp
@ 2010-08-20 20:28           ` Josh Berry
  2010-08-21  4:51             ` James Smith
  0 siblings, 1 reply; 26+ messages in thread
From: Josh Berry @ 2010-08-20 20:28 UTC (permalink / raw)
  To: Andreas Philipp; +Cc: kreijack, linux-btrfs

On Fri, Aug 20, 2010 at 12:00, Andreas Philipp
<philipp.andreas@gmail.com> wrote:
> =C2=A0On 20.08.2010 20:49, Josh Berry wrote:
>>
>> On Fri, Aug 20, 2010 at 11:34, Andreas Philipp
>> <philipp.andreas@gmail.com> =C2=A0wrote:
>>>
>>> =C2=A0On 20.08.2010 20:27, Josh Berry wrote:
>>>>
>>>> On Fri, Aug 20, 2010 at 05:03, Goffredo Baroncelli<kreijack@gmail.=
com>
>>>> =C2=A0wrote:
>>>>>
>>>>> On Thursday, 19 August, 2010, James Smith wrote:
>>>>>>
>>>>>> This patch randomizes the error codes and also fixes up some typ=
os
>>>>>
>>>>> including
>>>>>>
>>>>>> capitalization in the output.
>>>>>>
>>>>>> It would almost be nice to see a translation effort for the tool=
 as
>>>>>> well.
>>>>
>>>> [...]
>>>>>
>>>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 fprintf(stderr, "ERR-A.11: in command '");
>>>>>
>>>>> I am not against this kind of error codes, but I prefer
>>>>>
>>>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 fprintf(stderr, "Error 'ERR-A.11' in command
>>>>> '");
>>>>
>>>> As a layman/end user, I disagree. =C2=A0The former format is easie=
r for
>>>> shell scripts and the like to parse -- the error code can be extra=
cted
>>>> with a simple "cut -d: -f1".
>>>
>>> This makes no difference. A simple `cut -d " " -f1` would do the jo=
b in
>>> the
>>> second case.
>>
>> I think you meant -f2, and that still leaves the quotes hanging
>> around. =C2=A0So you'd need to cut -d" " -f2 |tr -d "'" . =C2=A0It's=
 not a big
>> deal either way, I just think the former is easier to work with.
>
> Sorry, of course -f2. But why not simply cut -d "'" -f 2?

Oh right, good point. :)  Though as Goffredo said, using the error
code is probably better anyway.

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 18:49       ` Josh Berry
  2010-08-20 19:00         ` Andreas Philipp
@ 2010-08-20 19:03         ` Goffredo Baroncelli
  1 sibling, 0 replies; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-08-20 19:03 UTC (permalink / raw)
  To: linux-btrfs

On Friday, 20 August, 2010, Josh Berry wrote:
> On Fri, Aug 20, 2010 at 11:34, Andreas Philipp
> <philipp.andreas@gmail.com> wrote:
> >  On 20.08.2010 20:27, Josh Berry wrote:
> >>
> >> On Fri, Aug 20, 2010 at 05:03, Goffredo Baroncelli<kreijack@gmail.com>
> >>  wrote:
> >>>
> >>> On Thursday, 19 August, 2010, James Smith wrote:
> >>>>
> >>>> This patch randomizes the error codes and also fixes up some typos
> >>>
> >>> including
> >>>>
> >>>> capitalization in the output.
> >>>>
> >>>> It would almost be nice to see a translation effort for the tool as
> >>>> well.
> >>
> >> [...]
> >>>
> >>> +                       fprintf(stderr, "ERR-A.11: in command '");
> >>>
> >>> I am not against this kind of error codes, but I prefer
> >>>
> >>> +                       fprintf(stderr, "Error 'ERR-A.11' in command 
'");
> >>
> >> As a layman/end user, I disagree.  The former format is easier for
> >> shell scripts and the like to parse -- the error code can be extracted
> >> with a simple "cut -d: -f1".
> >
> > This makes no difference. A simple `cut -d " " -f1` would do the job in 
the
> > second case.
> 
> I think you meant -f2, and that still leaves the quotes hanging
> around.  So you'd need to cut -d" " -f2 |tr -d "'" .  It's not a big
> deal either way, I just think the former is easier to work with.


Why do not use the exit() return value ? My goal when I wrote btrfs, was a 
clean up of the returned codes. The btrfsctl command (the old command) is a 
mess regarding this aspect. But btrfs should (modulo BUG) return 0 for a 
successful action and a value different to 0 for an error. I agree that these 
codes have to be documented in the man page.

> 
> -- Josh
> 


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 18:49       ` Josh Berry
@ 2010-08-20 19:00         ` Andreas Philipp
  2010-08-20 20:28           ` Josh Berry
  2010-08-20 19:03         ` Goffredo Baroncelli
  1 sibling, 1 reply; 26+ messages in thread
From: Andreas Philipp @ 2010-08-20 19:00 UTC (permalink / raw)
  To: Josh Berry; +Cc: kreijack, linux-btrfs

  On 20.08.2010 20:49, Josh Berry wrote:
> On Fri, Aug 20, 2010 at 11:34, Andreas Philipp
> <philipp.andreas@gmail.com>  wrote:
>>   On 20.08.2010 20:27, Josh Berry wrote:
>>> On Fri, Aug 20, 2010 at 05:03, Goffredo Baroncelli<kreijack@gmail.com>
>>>   wrote:
>>>> On Thursday, 19 August, 2010, James Smith wrote:
>>>>> This patch randomizes the error codes and also fixes up some typos
>>>> including
>>>>> capitalization in the output.
>>>>>
>>>>> It would almost be nice to see a translation effort for the tool as
>>>>> well.
>>> [...]
>>>> +                       fprintf(stderr, "ERR-A.11: in command '");
>>>>
>>>> I am not against this kind of error codes, but I prefer
>>>>
>>>> +                       fprintf(stderr, "Error 'ERR-A.11' in command '");
>>> As a layman/end user, I disagree.  The former format is easier for
>>> shell scripts and the like to parse -- the error code can be extracted
>>> with a simple "cut -d: -f1".
>> This makes no difference. A simple `cut -d " " -f1` would do the job in the
>> second case.
> I think you meant -f2, and that still leaves the quotes hanging
> around.  So you'd need to cut -d" " -f2 |tr -d "'" .  It's not a big
> deal either way, I just think the former is easier to work with.
Sorry, of course -f2. But why not simply cut -d "'" -f 2?
Andreas

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 14:42     ` Benjamin Griese
@ 2010-08-20 18:56       ` Goffredo Baroncelli
  0 siblings, 0 replies; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-08-20 18:56 UTC (permalink / raw)
  To: linux-btrfs

On Friday, 20 August, 2010, Benjamin Griese wrote:
> Hello guys,
> 
> I would also prefer doing it in an all-in-one tool with various parameters.
> I like the concept how the Solaris-Devs did it by consolidating every
> special configuration tool to an "xyzadm"-binary (idea: btrfsadm? i.e.
> similar to mdadm?).
> For me as an admin it is easier to remember only one command,
> especially when its neccessery to use it only from time to time.
> There exists only one manpage where every parameter is found (in theory). 
:)
> And for the devs (sorry, I'm not one of those guys ;) ) maybe its
> easier to maintain/improve only one binary + lib.
> 
> Just my opinion. :)

This is the reason of btrfs command. The aim of this command (which is quite 
new) is to groups all the btrfs related command. In fact, the btrfs command  
is able to replace btrfs-show, btrfs-vol, btrfsctl, which may be considered 
"obsolete". 
Regarding the other commands:

* btrfs-debug-tree, btrfs-map-logical, btrfs-image: are debugging commands. 
Not useful to a system administrator
* btrfsck: historically the fsck* program is a standalone program. And the 
btrfs one is not useful at all.
* mkfs.btrfs: same as above
* btrfs-convert, btrfstune: may be possible candidate for an inclusion in the 
btrfs program

But what is needed is not the request but the codes :-)


Regards
Goffredo

> 
> bye, benjamin
> 
> 
> On Fri, Aug 20, 2010 at 14:43, Jon Nelson <jnelson@jamponi.net> wrote:
> > On Fri, Aug 20, 2010 at 7:03 AM, Goffredo Baroncelli <kreijack@gmail.com> 
wrote:
> >>
> >>
> >> +                       fprintf(stderr, "ERR-A.11: in command '");
> >>
> >> I am not against this kind of error codes, but I prefer
> >>
> >> +                       fprintf(stderr, "Error 'ERR-A.11' in command 
'");
> >>
> >> And a file.txt which details the error codes (otherwise these errors are 
not
> >> very useful).
> >>
> >> Why some error codes contain a dot (see ERR-C.13) and others not (like 
ERR-
> >> A3) ?
> >
> > Goffredo Baroncelli - I think those are good comments!
> >
> > However, I would further suggest that when reporting an error code
> > that including the 'ERR-' prefix is redundant. Therefore, I propose:
> >
> > fprintf(stderr, "Error 'A.11' in command '");
> >
> > What does A. 11 refer to, anyway?
> >
> > --
> > Jon
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >
> 
> 
> 
> -- 
> To be or not to be -- Shakespeare | To do is to be -- Nietzsche | To
> be is to do -- Sartre | Do be do be do -- Sinatra
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 18:34     ` Andreas Philipp
@ 2010-08-20 18:49       ` Josh Berry
  2010-08-20 19:00         ` Andreas Philipp
  2010-08-20 19:03         ` Goffredo Baroncelli
  0 siblings, 2 replies; 26+ messages in thread
From: Josh Berry @ 2010-08-20 18:49 UTC (permalink / raw)
  To: Andreas Philipp; +Cc: kreijack, linux-btrfs

On Fri, Aug 20, 2010 at 11:34, Andreas Philipp
<philipp.andreas@gmail.com> wrote:
> =C2=A0On 20.08.2010 20:27, Josh Berry wrote:
>>
>> On Fri, Aug 20, 2010 at 05:03, Goffredo Baroncelli<kreijack@gmail.co=
m>
>> =C2=A0wrote:
>>>
>>> On Thursday, 19 August, 2010, James Smith wrote:
>>>>
>>>> This patch randomizes the error codes and also fixes up some typos
>>>
>>> including
>>>>
>>>> capitalization in the output.
>>>>
>>>> It would almost be nice to see a translation effort for the tool a=
s
>>>> well.
>>
>> [...]
>>>
>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 fprintf(stderr, "ERR-A.11: in command '");
>>>
>>> I am not against this kind of error codes, but I prefer
>>>
>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 fprintf(stderr, "Error 'ERR-A.11' in command '");
>>
>> As a layman/end user, I disagree. =C2=A0The former format is easier =
for
>> shell scripts and the like to parse -- the error code can be extract=
ed
>> with a simple "cut -d: -f1".
>
> This makes no difference. A simple `cut -d " " -f1` would do the job =
in the
> second case.

I think you meant -f2, and that still leaves the quotes hanging
around.  So you'd need to cut -d" " -f2 |tr -d "'" .  It's not a big
deal either way, I just think the former is easier to work with.

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 18:27   ` Josh Berry
@ 2010-08-20 18:34     ` Andreas Philipp
  2010-08-20 18:49       ` Josh Berry
  0 siblings, 1 reply; 26+ messages in thread
From: Andreas Philipp @ 2010-08-20 18:34 UTC (permalink / raw)
  To: Josh Berry; +Cc: kreijack, linux-btrfs

  On 20.08.2010 20:27, Josh Berry wrote:
> On Fri, Aug 20, 2010 at 05:03, Goffredo Baroncelli<kreijack@gmail.com>  wrote:
>> On Thursday, 19 August, 2010, James Smith wrote:
>>> This patch randomizes the error codes and also fixes up some typos
>> including
>>> capitalization in the output.
>>>
>>> It would almost be nice to see a translation effort for the tool as well.
> [...]
>> +                       fprintf(stderr, "ERR-A.11: in command '");
>>
>> I am not against this kind of error codes, but I prefer
>>
>> +                       fprintf(stderr, "Error 'ERR-A.11' in command '");
> As a layman/end user, I disagree.  The former format is easier for
> shell scripts and the like to parse -- the error code can be extracted
> with a simple "cut -d: -f1".
This makes no difference. A simple `cut -d " " -f1` would do the job in 
the second case.
Andreas
> (In fact, I wish the output from things like "btrfs filesystem df",
> "show", etc. were easier to parse, but that's a separate issue. :) )
>
> -- Josh
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 12:03 ` Goffredo Baroncelli
  2010-08-20 12:43   ` Jon Nelson
@ 2010-08-20 18:27   ` Josh Berry
  2010-08-20 18:34     ` Andreas Philipp
  1 sibling, 1 reply; 26+ messages in thread
From: Josh Berry @ 2010-08-20 18:27 UTC (permalink / raw)
  To: kreijack; +Cc: linux-btrfs

On Fri, Aug 20, 2010 at 05:03, Goffredo Baroncelli <kreijack@gmail.com>=
 wrote:
> On Thursday, 19 August, 2010, James Smith wrote:
>> This patch randomizes the error codes and also fixes up some typos
> including
>> capitalization in the output.
>>
>> It would almost be nice to see a translation effort for the tool as =
well.
[...]
>
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 fprintf(stderr, "ERR-A.11: in command '");
>
> I am not against this kind of error codes, but I prefer
>
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 fprintf(stderr, "Error 'ERR-A.11' in command '");

As a layman/end user, I disagree.  The former format is easier for
shell scripts and the like to parse -- the error code can be extracted
with a simple "cut -d: -f1".

(In fact, I wish the output from things like "btrfs filesystem df",
"show", etc. were easier to parse, but that's a separate issue. :) )

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 12:43   ` Jon Nelson
@ 2010-08-20 14:42     ` Benjamin Griese
  2010-08-20 18:56       ` Goffredo Baroncelli
  0 siblings, 1 reply; 26+ messages in thread
From: Benjamin Griese @ 2010-08-20 14:42 UTC (permalink / raw)
  To: Jon Nelson; +Cc: linux-btrfs

Hello guys,

I would also prefer doing it in an all-in-one tool with various paramet=
ers.
I like the concept how the Solaris-Devs did it by consolidating every
special configuration tool to an "xyzadm"-binary (idea: btrfsadm? i.e.
similar to mdadm?).
=46or me as an admin it is easier to remember only one command,
especially when its neccessery to use it only from time to time.
There exists only one manpage where every parameter is found (in theory=
). :)
And for the devs (sorry, I'm not one of those guys ;) ) maybe its
easier to maintain/improve only one binary + lib.

Just my opinion. :)

bye, benjamin


On Fri, Aug 20, 2010 at 14:43, Jon Nelson <jnelson@jamponi.net> wrote:
> On Fri, Aug 20, 2010 at 7:03 AM, Goffredo Baroncelli <kreijack@gmail.=
com> wrote:
>>
>>
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fprintf(stderr, "ERR-A=
=2E11: in command '");
>>
>> I am not against this kind of error codes, but I prefer
>>
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fprintf(stderr, "Error=
 'ERR-A.11' in command '");
>>
>> And a file.txt which details the error codes (otherwise these errors=
 are not
>> very useful).
>>
>> Why some error codes contain a dot (see ERR-C.13) and others not (li=
ke ERR-
>> A3) ?
>
> Goffredo Baroncelli - I think those are good comments!
>
> However, I would further suggest that when reporting an error code
> that including the 'ERR-' prefix is redundant. Therefore, I propose:
>
> fprintf(stderr, "Error 'A.11' in command '");
>
> What does A. 11 refer to, anyway?
>
> --
> Jon
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs=
" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at =A0http://vger.kernel.org/majordomo-info.html
>



--=20
To be or not to be -- Shakespeare | To do is to be -- Nietzsche | To
be is to do -- Sartre | Do be do be do -- Sinatra
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-20 12:03 ` Goffredo Baroncelli
@ 2010-08-20 12:43   ` Jon Nelson
  2010-08-20 14:42     ` Benjamin Griese
  2010-08-20 18:27   ` Josh Berry
  1 sibling, 1 reply; 26+ messages in thread
From: Jon Nelson @ 2010-08-20 12:43 UTC (permalink / raw)
  Cc: linux-btrfs

On Fri, Aug 20, 2010 at 7:03 AM, Goffredo Baroncelli <kreijack@gmail.co=
m> wrote:
>
>
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 fprintf(stderr, "ERR-A.11: in command '");
>
> I am not against this kind of error codes, but I prefer
>
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 fprintf(stderr, "Error 'ERR-A.11' in command '");
>
> And a file.txt which details the error codes (otherwise these errors =
are not
> very useful).
>
> Why some error codes contain a dot (see ERR-C.13) and others not (lik=
e ERR-
> A3) ?

Goffredo Baroncelli - I think those are good comments!

However, I would further suggest that when reporting an error code
that including the 'ERR-' prefix is redundant. Therefore, I propose:

fprintf(stderr, "Error 'A.11' in command '");

What does A. 11 refer to, anyway?

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
@ 2010-08-20 12:12 Goffredo Baroncelli
  0 siblings, 0 replies; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-08-20 12:12 UTC (permalink / raw)
  To: linux-btrfs

On Friday, 20 August, 2010, Goffredo Baroncelli wrote:
> On Thursday, 19 August, 2010, James Smith wrote:
> > This patch randomizes the error codes and also fixes up some typos 
> including
> > capitalization in the output.

I think that you should also update the btrfs man page in order to reflect 
your changing:
- the capitalization of the command arguments
- the list of error codes for every commands

Regards
G.Baroncelli


> > It would almost be nice to see a translation effort for the tool as well.
> > 
> 
> Hi James,
> 
> I don't comment the changing the capitalization. Regarding the other 
changes:
> 
> [...]
>  {
>  	struct Command *cp;
>  
> -	printf("Usage:\n");
> +	printf("VFS-2593 %s\n", BTRFS_BUILD_VERSION);
>                 ^^^^^^^^
> 
> What means VFS-2593 ?
> 
> +	printf("\nNo matter where you go, there you are.\n");
> 
> Is it really useful this kind of comment ?
> 
> 
> [...]
> 
> +			fprintf(stderr, "ERR-A.11: in command '");
> 
> I am not against this kind of error codes, but I prefer
> 
> +			fprintf(stderr, "Error 'ERR-A.11' in command '");
> 
> And a file.txt which details the error codes (otherwise these errors are 
not 
> very useful).
> 
> Why some error codes contain a dot (see ERR-C.13) and others not (like ERR-
> A3) ?
> 
> 
> Reagrds
> G.Baroncelli
> 
> -- 
> gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) 
> <kreijackATinwind.it>
> Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
  2010-08-19 20:52 [RFC] Move all btrfs command to only one command James Smith
@ 2010-08-20 12:03 ` Goffredo Baroncelli
  2010-08-20 12:43   ` Jon Nelson
  2010-08-20 18:27   ` Josh Berry
  0 siblings, 2 replies; 26+ messages in thread
From: Goffredo Baroncelli @ 2010-08-20 12:03 UTC (permalink / raw)
  To: linux-btrfs

On Thursday, 19 August, 2010, James Smith wrote:
> This patch randomizes the error codes and also fixes up some typos 
including
> capitalization in the output.
> 
> It would almost be nice to see a translation effort for the tool as well.
> 

Hi James,

I don't comment the changing the capitalization. Regarding the other changes:

[...]
 {
 	struct Command *cp;
 
-	printf("Usage:\n");
+	printf("VFS-2593 %s\n", BTRFS_BUILD_VERSION);
                ^^^^^^^^

What means VFS-2593 ?

+	printf("\nNo matter where you go, there you are.\n");

Is it really useful this kind of comment ?


[...]

+			fprintf(stderr, "ERR-A.11: in command '");

I am not against this kind of error codes, but I prefer

+			fprintf(stderr, "Error 'ERR-A.11' in command '");

And a file.txt which details the error codes (otherwise these errors are not 
very useful).

Why some error codes contain a dot (see ERR-C.13) and others not (like ERR-
A3) ?


Reagrds
G.Baroncelli

-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) 
<kreijackATinwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC] Move all btrfs command to only one command
@ 2010-08-19 20:52 James Smith
  2010-08-20 12:03 ` Goffredo Baroncelli
  0 siblings, 1 reply; 26+ messages in thread
From: James Smith @ 2010-08-19 20:52 UTC (permalink / raw)
  To: linux-btrfs

[-- Attachment #1: Type: text/plain, Size: 182 bytes --]

This patch randomizes the error codes and also fixes up some typos including
capitalization in the output.

It would almost be nice to see a translation effort for the tool as well.

[-- Attachment #2: errcodes.diff --]
[-- Type: text/plain, Size: 15033 bytes --]

diff --git a/btrfs.c b/btrfs.c
index 4d263c4..3418837 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -44,52 +44,52 @@ static struct Command commands[] = {
 		avoid short commands different for the case only
 	*/
 	{ do_clone, 2,
-	  "subvolume snapshot", "<source> [<dest>/]<name>\n"
-		"Create a writable snapshot of the subvolume <source> with\n"
-		"the name <name> in the <dest> directory."
+	  "subvolume snapshot", "<Source> [<Dest>/]<Name>\n"
+		"Create a writable snapshot of the subvolume <Source> with\n"
+		"the name <Name> in the <Dest> directory."
 	},
 	{ do_delete_subvolume, 1,
-	  "subvolume delete", "<subvolume>\n"
-		"Delete the subvolume <subvolume>."
+	  "subvolume delete", "<Subvolume>\n"
+		"Delete the subvolume <Subvolume>."
 	},
 	{ do_create_subvol, 1,
-	  "subvolume create", "[<dest>/]<name>\n"
-		"Create a subvolume in <dest> (or the current directory if\n"
+	  "subvolume create", "[<Dest>/]<Name>\n"
+		"Create a subvolume in <Dest> (or the current directory if\n"
 		"not passed)."
 	},
 	{ do_defrag, -1,
-	  "filesystem defragment", "<file>|<dir> [<file>|<dir>...]\n"
+	  "filesystem defragment", "<File>|<Dir> [<File>|<Dir>...]\n"
 		"Defragment a file or a directory."
 	},
 	{ do_fssync, 1,
-	  "filesystem sync", "<path>\n"
-		"Force a sync on the filesystem <path>."
+	  "filesystem sync", "<Path>\n"
+		"Force a sync on the filesystem <Path>."
 	},
 	{ do_resize, 2,
-	  "filesystem resize", "[+/-]<newsize>[gkm]|max <filesystem>\n"
+	  "filesystem resize", "[+/-]<Newsize>[gkm]|max <Filesystem>\n"
 		"Resize the file system. If 'max' is passed, the filesystem\n"
-		"will occupe all available space on the device."
+		"will occupy all available space on the device."
 	},
 	{ do_show_filesystem, 999,
-	  "filesystem show", "[<uuid>|<label>]\n"
-		"Show the info of a btrfs filesystem. If no <uuid> or <label>\n"
-		"is passed, info of all the btrfs filesystem are shown."
+	  "filesystem show", "[<UUID>|<Label>]\n"
+		"Show all info about specific BTRFS filesystems. If no <UUID> or <Label>\n"
+		"is passed, information from all the BTRFS filesystems are shown."
 	},
 	{ do_balance, 1,
-	  "filesystem balance", "<path>\n"
+	  "filesystem balance", "<Path>\n"
 		"Balance the chunks across the device."
 	},
 	{ do_scan,
-	  999, "device scan", "[<device> [<device>..]\n"
-		"Scan all device for or the passed device for a btrfs\n"
+	  999, "device scan", "[<Device> [<Device>..]\n"
+		"Scan all devices or the passed device for a BTRFS\n"
 		"filesystem."
 	},	
 	{ do_add_volume, -1,
-	  "device add", "<dev> [<dev>..] <path>\n"
+	  "device add", "<Device> [<Device>..] <Path>\n"
 		"Add a device to a filesystem."
 	},
 	{ do_remove_volume, -1,
-	  "device delete", "<dev> [<dev>..] <path>\n"
+	  "device delete", "<Device> [<Device>..] <Path>\n"
 		"Remove a device from a filesystem."
 	},
 	/* coming soon
@@ -134,12 +134,13 @@ static void help(char *np)
 {
 	struct Command *cp;
 
-	printf("Usage:\n");
+	printf("VFS-2593 %s\n", BTRFS_BUILD_VERSION);
+	printf("\nNo matter where you go, there you are.\n");
+	printf("\nUsage:\n");
 	for( cp = commands; cp->verb; cp++ )
 		print_help(np, cp);
 
-	printf("\n\t%s help|--help|-h\n\t\tShow the help.\n",np);
-	printf("\n%s\n", BTRFS_BUILD_VERSION);
+	printf("\n\t%s help|--help|-h\n\t\tShow help.\n",np);
 }
 
 static int split_command(char *cmd, char ***commands)
@@ -195,7 +196,7 @@ static int check_ambiguity(struct Command *cmd, char **argv){
 		}
 		if(match){
 			int j;
-			fprintf(stderr, "ERROR: in command '");
+			fprintf(stderr, "ERR-A.11: in command '");
 			for( j = 0 ; j <= i ; j++ )
 				fprintf(stderr, "%s%s",j?" ":"", argv[j+1]);
 			fprintf(stderr, "', '%s' is ambiguous\n",argv[j]);
@@ -291,7 +292,7 @@ static int parse_args(int argc, char **argv,
 	}
 
 	if(!matchcmd){
-		fprintf( stderr, "ERROR: unknow command '%s'\n",argv[1]);
+		fprintf( stderr, "ERR-B.12: unknown command '%s'\n",argv[1]);
 		help(prgname);
 		return -1;
 	}
@@ -301,12 +302,12 @@ static int parse_args(int argc, char **argv,
 
 	/* check the number of argument */
 	if (matchcmd->nargs < 0 && matchcmd->nargs < -*nargs_ ){
-		fprintf(stderr, "ERROR: '%s' requires minimum %d arg(s)\n",
+		fprintf(stderr, "ERR-C.13: '%s' requires minimum %d arg(s)\n",
 			matchcmd->verb, -matchcmd->nargs);
 			return -2;
 	}
 	if(matchcmd->nargs >= 0 && matchcmd->nargs != *nargs_ && matchcmd->nargs != 999 ){
-		fprintf(stderr, "ERROR: '%s' requires %d arg(s)\n",
+		fprintf(stderr, "ERR-D.14: '%s' requires %d arg(s)\n",
 			matchcmd->verb, matchcmd->nargs);
 			return -2;
 	}
diff --git a/btrfs_cmds.c b/btrfs_cmds.c
index e112902..9475ac6 100644
--- a/btrfs_cmds.c
+++ b/btrfs_cmds.c
@@ -128,17 +128,17 @@ int do_clone(int argc, char **argv)
 
 	res = test_issubvolume(subvol);
 	if(res<0){
-		fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
+		fprintf(stderr, "ERR-A1: Error accessing '%s'\n", subvol);
 		return 12;
 	}
 	if(!res){
-		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
+		fprintf(stderr, "ERR-A2: '%s' is not a subvolume\n", subvol);
 		return 13;
 	}
 
 	res = test_isdir(dst);
 	if(res == 0 ){
-		fprintf(stderr, "ERROR: '%s' exists and it is not a directory\n", dst);
+		fprintf(stderr, "ERR-A3: '%s' exists and it is not a directory\n", dst);
 		return 12;
 	}
 
@@ -155,28 +155,28 @@ int do_clone(int argc, char **argv)
 
 	if( !strcmp(newname,".") || !strcmp(newname,"..") ||
 	     strchr(newname, '/') ){
-		fprintf(stderr, "ERROR: uncorrect snapshot name ('%s')\n",
+		fprintf(stderr, "ERR-B1: Uncorrect snapshot name ('%s')\n",
 			newname);
 		return 14;
 	}
 
 	len = strlen(newname);
 	if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
-		fprintf(stderr, "ERROR: snapshot name too long ('%s)\n",
+		fprintf(stderr, "ERR-B2: Snapshot name too long ('%s)\n",
 			newname);
 		return 14;
 	}
 
 	fddst = open_file_or_dir(dstdir);
 	if (fddst < 0) {
-		fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
+		fprintf(stderr, "ERR-B3: Can't access to '%s'\n", dstdir);
 		return 12;
 	}
 
 	fd = open_file_or_dir(subvol);
 	if (fd < 0) {
 		close(fddst);
-		fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
+		fprintf(stderr, "ERR-B4: Can't access to '%s'\n", dstdir);
 		return 12;
 	}
 
@@ -190,7 +190,7 @@ int do_clone(int argc, char **argv)
 	close(fddst);
 
 	if(res < 0 ){
-		fprintf( stderr, "ERROR: cannot snapshot '%s'\n",subvol);
+		fprintf( stderr, "ERR-B5: Cannot snapshot '%s'\n",subvol);
 		return 11;
 	}
 
@@ -207,11 +207,11 @@ int do_delete_subvolume(int argc, char **argv)
 
 	res = test_issubvolume(path);
 	if(res<0){
-		fprintf(stderr, "ERROR: error accessing '%s'\n", path);
+		fprintf(stderr, "ERR-C1: Error accessing '%s'\n", path);
 		return 12;
 	}
 	if(!res){
-		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", path);
+		fprintf(stderr, "ERR-C2: '%s' is not a subvolume\n", path);
 		return 13;
 	}
 
@@ -224,14 +224,14 @@ int do_delete_subvolume(int argc, char **argv)
 
 	if( !strcmp(vname,".") || !strcmp(vname,"..") ||
 	     strchr(vname, '/') ){
-		fprintf(stderr, "ERROR: uncorrect subvolume name ('%s')\n",
+		fprintf(stderr, "ERR-C3: Incorrect subvolume name ('%s')\n",
 			vname);
 		return 14;
 	}
 
 	len = strlen(vname);
 	if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
-		fprintf(stderr, "ERROR: snapshot name too long ('%s)\n",
+		fprintf(stderr, "ERR-C4: Snapshot name too long ('%s)\n",
 			vname);
 		return 14;
 	}
@@ -239,7 +239,7 @@ int do_delete_subvolume(int argc, char **argv)
 	fd = open_file_or_dir(dname);
 	if (fd < 0) {
 		close(fd);
-		fprintf(stderr, "ERROR: can't access to '%s'\n", dname);
+		fprintf(stderr, "ERR-C5: Can't access to '%s'\n", dname);
 		return 12;
 	}
 
@@ -250,7 +250,7 @@ int do_delete_subvolume(int argc, char **argv)
 	close(fd);
 
 	if(res < 0 ){
-		fprintf( stderr, "ERROR: cannot delete '%s/%s'\n",dname, vname);
+		fprintf( stderr, "ERR-C6: Cannot delete '%s/%s'\n",dname, vname);
 		return 11;
 	}
 
@@ -268,7 +268,7 @@ int do_create_subvol(int argc, char **argv)
 
 	res = test_isdir(dst);
 	if(res >= 0 ){
-		fprintf(stderr, "ERROR: '%s' exists\n", dst);
+		fprintf(stderr, "ERR-D1: '%s' exists\n", dst);
 		return 12;
 	}
 
@@ -279,21 +279,21 @@ int do_create_subvol(int argc, char **argv)
 
 	if( !strcmp(newname,".") || !strcmp(newname,"..") ||
 	     strchr(newname, '/') ){
-		fprintf(stderr, "ERROR: uncorrect subvolume name ('%s')\n",
+		fprintf(stderr, "ERR-D2: Incorrect subvolume name ('%s')\n",
 			newname);
 		return 14;
 	}
 	
 	len = strlen(newname);
 	if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
-		fprintf(stderr, "ERROR: subvolume name too long ('%s)\n",
+		fprintf(stderr, "ERR-D3: Subvolume name too long ('%s)\n",
 			newname);
 		return 14;
 	}
 
 	fddst = open_file_or_dir(dstdir);
 	if (fddst < 0) {
-		fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
+		fprintf(stderr, "ERR-D4: Can't access to '%s'\n", dstdir);
 		return 12;
 	}
 
@@ -304,7 +304,7 @@ int do_create_subvol(int argc, char **argv)
 	close(fddst);
 
 	if(res < 0 ){
-		fprintf( stderr, "ERROR: cannot create subvolume\n");
+		fprintf( stderr, "ERR-D5: Cannot create subvolume\n");
 		return 11;
 	}
 
@@ -319,7 +319,7 @@ int do_fssync(int argc, char **argv)
 
 	fd = open_file_or_dir(path);
 	if (fd < 0) {
-		fprintf(stderr, "ERROR: can't access to '%s'\n", path);
+		fprintf(stderr, "ERR-D6: Can't access to '%s'\n", path);
 		return 12;
 	}
 
@@ -327,7 +327,7 @@ int do_fssync(int argc, char **argv)
 	res = ioctl(fd, BTRFS_IOC_SYNC);
 	close(fd);
 	if( res < 0 ){
-		fprintf(stderr, "ERROR: unable to fs-syncing '%s'\n", path);
+		fprintf(stderr, "ERR-D7: Unable to drop-sync '%s'\n", path);
 		return 16;
 	}
 
@@ -343,7 +343,7 @@ int do_scan(int nargs, char **argv)
 		printf("Scanning for Btrfs filesystems\n");
 		ret = btrfs_scan_one_dir("/dev", 1);
 		if (ret){
-			fprintf(stderr, "ERROR: error %d while scanning\n", ret);
+			fprintf(stderr, "ERR-E1: Error %d while scanning\n", ret);
 			return 18;
 		}
 		return 0;
@@ -351,7 +351,7 @@ int do_scan(int nargs, char **argv)
 
 	fd = open("/dev/btrfs-control", O_RDWR);
 	if (fd < 0) {
-		perror("failed to open /dev/btrfs-control");
+		perror("ERR-E2: Failed to open /dev/btrfs-control");
 		return 10;
 	}
 
@@ -371,7 +371,7 @@ int do_scan(int nargs, char **argv)
 
 		if( ret < 0 ){
 			close(fd);
-			fprintf(stderr, "ERROR: unable to scan the device '%s'\n", argv[i]);
+			fprintf(stderr, "ERR-E3: Unable to scan the device '%s'\n", argv[i]);
 			return 11;
 		}
 	}
@@ -391,7 +391,7 @@ int do_defrag(int argc, char **argv)
 		char	*path = argv[i];
 		fd = open_file_or_dir(path);
 		if (fd < 0) {
-			fprintf(stderr, "ERROR: can't access to '%s'\n", path);
+			fprintf(stderr, "ERR-F1: Can't access to '%s'\n", path);
 			ret++;
 			continue;
 		}
@@ -400,7 +400,7 @@ int do_defrag(int argc, char **argv)
 		res = ioctl(fd, BTRFS_IOC_DEFRAG);
 		close(fd);
 		if( res < 0 ){
-			fprintf(stderr, "ERROR: unable to defrag '%s'\n", argv[i]);
+			fprintf(stderr, "ERR-F2: Unable to defragment '%s'\n", argv[i]);
 			ret++;
 			continue;
 		}
@@ -423,22 +423,22 @@ int do_resize(int argc, char **argv)
 	
 	fd = open_file_or_dir(path);
 	if (fd < 0) {
-		fprintf(stderr, "ERROR: can't access to '%s'\n", path);
+		fprintf(stderr, "ERR-G1: Can't access to '%s'\n", path);
 		return 12;
 	}
 	len = strlen(amount);
 	if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
-		fprintf(stderr, "ERROR: size value too long ('%s)\n",
+		fprintf(stderr, "ERR-G2: Size value too long ('%s)\n",
 			amount);
 		return 14;
 	}
 
-	printf("Resize '%s' of '%s'\n", path, amount);
+	printf("Resizing '%s' of '%s'\n", path, amount);
 	strcpy(args.name, amount);
 	res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
 	close(fd);
 	if( res < 0 ){
-		fprintf(stderr, "ERROR: unable to resize '%s'\n", path);
+		fprintf(stderr, "ERR-G3: Unable to resize '%s'\n", path);
 		return 30;
 	}
 	return 0;
@@ -497,7 +497,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
 		devs_found++;
 	}
 	if (devs_found < total) {
-		printf("\t*** Some devices missing\n");
+		printf("\t *** Some devices missing\n");
 	}
 	printf("\n");
 }
@@ -512,7 +512,7 @@ int do_show_filesystem(int argc, char **argv)
 
 	ret = btrfs_scan_one_dir("/dev", 0);
 	if (ret){
-		fprintf(stderr, "ERROR: error %d while scanning\n", ret);
+		fprintf(stderr, "ERR-H1: Error %d while scanning\n", ret);
 		return 18;
 	}
 
@@ -537,7 +537,7 @@ int do_add_volume(int nargs, char **args)
 
 	fdmnt = open_file_or_dir(mntpnt);
 	if (fdmnt < 0) {
-		fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt);
+		fprintf(stderr, "ERR-I1: Can't access to '%s'\n", mntpnt);
 		return 12;
 	}
 
@@ -549,20 +549,20 @@ int do_add_volume(int nargs, char **args)
 
 		devfd = open(args[i], O_RDWR);
 		if (!devfd) {
-			fprintf(stderr, "ERROR: Unable to open device '%s'\n", args[i]);
+			fprintf(stderr, "ERR-I2: Unable to open device '%s'\n", args[i]);
 			close(devfd);
 			ret++;
 			continue;
 		}
 		ret = fstat(devfd, &st);
 		if (ret) {
-			fprintf(stderr, "ERROR: Unable to stat '%s'\n", args[i]);
+			fprintf(stderr, "ERR-I3: Unable to stat '%s'\n", args[i]);
 			close(devfd);
 			ret++;
 			continue;
 		}
 		if (!S_ISBLK(st.st_mode)) {
-			fprintf(stderr, "ERROR: '%s' is not a block device\n", args[i]);
+			fprintf(stderr, "ERR-I4: '%s' is not a block device\n", args[i]);
 			close(devfd);
 			ret++;
 			continue;
@@ -570,7 +570,7 @@ int do_add_volume(int nargs, char **args)
 
 		res = btrfs_prepare_device(devfd, args[i], 1, &dev_block_count);
 		if (ret) {
-			fprintf(stderr, "ERROR: Unable to init '%s'\n", args[i]);
+			fprintf(stderr, "ERR-I5: Unable to init '%s'\n", args[i]);
 			close(devfd);
 			ret++;
 			continue;
@@ -580,7 +580,7 @@ int do_add_volume(int nargs, char **args)
 		strcpy(ioctl_args.name, args[i]);
 		res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
 		if(res<0){
-			fprintf(stderr, "ERROR: error adding the device '%s'\n", args[i]);
+			fprintf(stderr, "ERR-I6: Error adding the device '%s'\n", args[i]);
 			ret++;
 		}
 
@@ -602,14 +602,14 @@ int do_balance(int argc, char **argv)
 
 	fdmnt = open_file_or_dir(path);
 	if (fdmnt < 0) {
-		fprintf(stderr, "ERROR: can't access to '%s'\n", path);
+		fprintf(stderr, "ERR-J1: Can't access to '%s'\n", path);
 		return 12;
 	}
 
 	ret = ioctl(fdmnt, BTRFS_IOC_BALANCE);
 	close(fdmnt);
 	if(ret<0){
-		fprintf(stderr, "ERROR: balancing '%s'\n", path);
+		fprintf(stderr, "ERR-J2: Balancing '%s'\n", path);
 
 		return 19;
 	}
@@ -623,7 +623,7 @@ int do_remove_volume(int nargs, char **args)
 
 	fdmnt = open_file_or_dir(mntpnt);
 	if (fdmnt < 0) {
-		fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt);
+		fprintf(stderr, "ERR-K1: Can't access to '%s'\n", mntpnt);
 		return 12;
 	}
 
@@ -634,7 +634,7 @@ int do_remove_volume(int nargs, char **args)
 		strcpy(arg.name, args[i]);
 		res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
 		if(res<0){
-			fprintf(stderr, "ERROR: error removing the device '%s'\n", args[i]);
+			fprintf(stderr, "ERR-K2: Error removing the device '%s'\n", args[i]);
 			ret++;
 		}
 	}

^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2010-08-27  3:38 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-21 19:29 [RFC] Move all btrfs command to only one command Goffredo Baroncelli
2010-01-22  0:02 ` TARUISI Hiroaki
2010-01-22  0:11 ` Michael Niederle
2010-01-22  9:33   ` Xavier Nicollet
2010-01-22  8:23 ` Adrian von Bidder
2010-01-24 17:35 ` [RFC] Move all btrfs command to only one command: btrfs.c Goffredo Baroncelli
2010-01-24 18:34   ` Piavlo
2010-02-11 16:33   ` Chris Mason
2010-02-11 18:15     ` Goffredo Baroncelli
2010-02-11 21:20     ` rk
2010-02-11 21:29       ` Goffredo Baroncelli
2010-08-19 20:52 [RFC] Move all btrfs command to only one command James Smith
2010-08-20 12:03 ` Goffredo Baroncelli
2010-08-20 12:43   ` Jon Nelson
2010-08-20 14:42     ` Benjamin Griese
2010-08-20 18:56       ` Goffredo Baroncelli
2010-08-20 18:27   ` Josh Berry
2010-08-20 18:34     ` Andreas Philipp
2010-08-20 18:49       ` Josh Berry
2010-08-20 19:00         ` Andreas Philipp
2010-08-20 20:28           ` Josh Berry
2010-08-21  4:51             ` James Smith
2010-08-21  9:37               ` Goffredo Baroncelli
     [not found]                 ` <AANLkTikJd8bDU1Eq22u0+yQ8eBCUn3OXHoE5E7uy+SG=@mail.gmail.com>
     [not found]                   ` <AANLkTi=VpZv26jntJ8mwmxtjnQ5LDOn_MSm6VtEhJ1CB@mail.gmail.com>
2010-08-27  3:38                     ` James Smith
2010-08-20 19:03         ` Goffredo Baroncelli
2010-08-20 12:12 Goffredo Baroncelli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).