linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: use btrfs error code for kernel errors
@ 2013-08-20  6:10 Anand Jain
  2013-08-20  6:10 ` [PATCH] btrfs: return btrfs error code for dev excl ops err Anand Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Anand Jain @ 2013-08-20  6:10 UTC (permalink / raw)
  To: linux-btrfs

Now with the below kernel patch, the excl operations like dev
add/replace/resize and balance returns the btrfs error
code defined in btrfs.h, this patch will help btrfs-progs
(and thus user) to know the error string on the terminal
(instead of /var/log/messages as previously kernel did).

This patch depends on the btrfs kernel patch:
  btrfs: return btrfs error code for dev excl ops err

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-balance.c    |   15 +++++++++++++++
 cmds-device.c     |    7 ++++++-
 cmds-filesystem.c |    6 +++++-
 cmds-replace.c    |    7 ++++++-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/cmds-balance.c b/cmds-balance.c
index c78b726..30019be 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -316,6 +316,12 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 			if (ret == 0)
 				goto out;
 			e = errno;
+			if (ret > 0) {
+				fprintf(stderr,
+					"ERROR: Balance failed due to - %s\n",
+					btrfs_err_str(ret));
+				goto out;
+			}
 		}
 
 		if (e == ECANCELED) {
@@ -332,6 +338,11 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 					"syslog - try dmesg | tail\n");
 			ret = 19;
 		}
+	} else if (ret > 0) {
+		fprintf(stderr,
+			"ERROR: Balance start failed - %s\n",
+			btrfs_err_str(ret));
+		ret = 1;
 	} else {
 		printf("Done, had to relocate %llu out of %llu chunks\n",
 		       (unsigned long long)args->stat.completed,
@@ -603,6 +614,10 @@ static int cmd_balance_resume(int argc, char **argv)
 "There may be more info in syslog - try dmesg | tail\n", path, strerror(e));
 			return 19;
 		}
+	} else if (ret > 0) {
+		fprintf(stderr,
+			"ERROR: Balance resume failed - %s\n",
+			btrfs_err_str(ret));
 	} else {
 		printf("Done, had to relocate %llu out of %llu chunks\n",
 		       (unsigned long long)args.stat.completed,
diff --git a/cmds-device.c b/cmds-device.c
index 833ad30..282590c 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -120,10 +120,15 @@ static int cmd_add_dev(int argc, char **argv)
 		strncpy_null(ioctl_args.name, argv[i]);
 		res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
 		e = errno;
-		if(res<0){
+		if (res < 0) {
 			fprintf(stderr, "ERROR: error adding the device '%s' - %s\n",
 				argv[i], strerror(e));
 			ret++;
+		} else if (res > 0) {
+			fprintf(stderr,
+				"ERROR: adding the device '%s' - %s\n",
+				argv[i], btrfs_err_str(res));
+			ret = 1;
 		}
 
 	}
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index e78b95c..239bd3b 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -575,10 +575,14 @@ static int cmd_resize(int argc, char **argv)
 	res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
 	e = errno;
 	close_file_or_dir(fd, dirstream);
-	if( res < 0 ){
+	if (res < 0) {
 		fprintf(stderr, "ERROR: unable to resize '%s' - %s\n", 
 			path, strerror(e));
 		return 30;
+	} else if (res > 0) {
+		fprintf(stderr, "ERROR: resize failed - %s\n",
+			btrfs_err_str(res));
+		return res;
 	}
 	return 0;
 }
diff --git a/cmds-replace.c b/cmds-replace.c
index 8ed92c4..e3ff695 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -297,12 +297,17 @@ static int cmd_start_replace(int argc, char **argv)
 	start_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_START;
 	ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args);
 	if (do_not_background) {
-		if (ret) {
+		if (ret < 0) {
 			fprintf(stderr,
 				"ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %s, %s\n",
 				path, strerror(errno),
 				replace_dev_result2string(start_args.result));
 			goto leave_with_error;
+		} else if (ret > 0) {
+			fprintf(stderr,
+				"ERROR: replace start failed on %s - %s\n",
+				path, btrfs_err_str(ret));
+			goto leave_with_error;
 		}
 
 		if (start_args.result !=
-- 
1.7.1


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

* [PATCH] btrfs: return btrfs error code for dev excl ops err
  2013-08-20  6:10 [PATCH] btrfs-progs: use btrfs error code for kernel errors Anand Jain
@ 2013-08-20  6:10 ` Anand Jain
  2013-08-20 18:34   ` Josef Bacik
  2013-08-21  3:44   ` [PATCH v2] " Anand Jain
  2013-09-06  9:38 ` [PATCH 3/3] btrfs-progs: use btrfs error code for kernel errors Anand Jain
  2013-09-13 11:35 ` [PATCH] " Anand Jain
  2 siblings, 2 replies; 9+ messages in thread
From: Anand Jain @ 2013-08-20  6:10 UTC (permalink / raw)
  To: linux-btrfs

now threads can return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
as defined in btrfs.h for the dev excl operation error in
the FS, which means with this kernel would stop logging
(almost an user error) into the /var/log/messages

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/ioctl.c           |   12 ++++--------
 include/uapi/linux/btrfs.h |    3 +--
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 107c5f4..89f346c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1382,9 +1382,8 @@ static noinline int btrfs_ioctl_resize(struct file *file,
 
 	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
 			1)) {
-		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
 		mnt_drop_write_file(file);
-		return -EINVAL;
+		return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 	}
 
 	mutex_lock(&root->fs_info->volume_mutex);
@@ -2346,8 +2345,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
 
 	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
 			1)) {
-		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
-		return -EINVAL;
+		return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 	}
 
 	mutex_lock(&root->fs_info->volume_mutex);
@@ -3638,8 +3636,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root *root, void __user *arg)
 		if (atomic_xchg(
 			&root->fs_info->mutually_exclusive_operation_running,
 			1)) {
-			pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
-			ret = -EINPROGRESS;
+			ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 		} else {
 			ret = btrfs_dev_replace_start(root, p);
 			atomic_set(
@@ -3883,8 +3880,7 @@ again:
 	} else {
 		/* this is (1) */
 		mutex_unlock(&fs_info->balance_mutex);
-		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
-		ret = -EINVAL;
+		ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 		goto out;
 	}
 
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 90d7bd9..182305f 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -505,8 +505,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
 		case BTRFS_ERROR_DEV_ONLY_WRITABLE:
 			return "unable to remove the only writeable device";
 		case BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS:
-			return "add/delete/balance/replace/resize operation "\
-				"in progress";
+			return "add/delete/balance/replace/resize operation in progress";
 		default:
 			return NULL;
 	}
-- 
1.7.1


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

* Re: [PATCH] btrfs: return btrfs error code for dev excl ops err
  2013-08-20  6:10 ` [PATCH] btrfs: return btrfs error code for dev excl ops err Anand Jain
@ 2013-08-20 18:34   ` Josef Bacik
  2013-08-21  3:47     ` Anand Jain
  2013-09-02 16:59     ` David Sterba
  2013-08-21  3:44   ` [PATCH v2] " Anand Jain
  1 sibling, 2 replies; 9+ messages in thread
From: Josef Bacik @ 2013-08-20 18:34 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Tue, Aug 20, 2013 at 02:10:54PM +0800, Anand Jain wrote:
> now threads can return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
> as defined in btrfs.h for the dev excl operation error in
> the FS, which means with this kernel would stop logging
> (almost an user error) into the /var/log/messages
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/ioctl.c           |   12 ++++--------
>  include/uapi/linux/btrfs.h |    3 +--
>  2 files changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 107c5f4..89f346c 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1382,9 +1382,8 @@ static noinline int btrfs_ioctl_resize(struct file *file,
>  
>  	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
>  			1)) {
> -		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
>  		mnt_drop_write_file(file);
> -		return -EINVAL;
> +		return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
>  	}
>  
>  	mutex_lock(&root->fs_info->volume_mutex);
> @@ -2346,8 +2345,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
>  
>  	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
>  			1)) {
> -		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
> -		return -EINVAL;
> +		return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
>  	}
>  
>  	mutex_lock(&root->fs_info->volume_mutex);
> @@ -3638,8 +3636,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root *root, void __user *arg)
>  		if (atomic_xchg(
>  			&root->fs_info->mutually_exclusive_operation_running,
>  			1)) {
> -			pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
> -			ret = -EINPROGRESS;
> +			ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
>  		} else {
>  			ret = btrfs_dev_replace_start(root, p);
>  			atomic_set(
> @@ -3883,8 +3880,7 @@ again:
>  	} else {
>  		/* this is (1) */
>  		mutex_unlock(&fs_info->balance_mutex);
> -		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
> -		ret = -EINVAL;
> +		ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
>  		goto out;
>  	}
>  
> diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
> index 90d7bd9..182305f 100644
> --- a/include/uapi/linux/btrfs.h
> +++ b/include/uapi/linux/btrfs.h
> @@ -505,8 +505,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
>  		case BTRFS_ERROR_DEV_ONLY_WRITABLE:
>  			return "unable to remove the only writeable device";
>  		case BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS:
> -			return "add/delete/balance/replace/resize operation "\
> -				"in progress";
> +			return "add/delete/balance/replace/resize operation in progress";
>  		default:
>  			return NULL;

This is an unnecessary change.  Thanks,

Josef

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

* [PATCH v2] btrfs: return btrfs error code for dev excl ops err
  2013-08-20  6:10 ` [PATCH] btrfs: return btrfs error code for dev excl ops err Anand Jain
  2013-08-20 18:34   ` Josef Bacik
@ 2013-08-21  3:44   ` Anand Jain
  1 sibling, 0 replies; 9+ messages in thread
From: Anand Jain @ 2013-08-21  3:44 UTC (permalink / raw)
  To: jbacik; +Cc: linux-btrfs

now threads can return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
as defined in btrfs.h for the dev excl operation error in
the FS, which means with this kernel would stop logging
(almost an user error) into the /var/log/messages

v2: accepts Josef' comment

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/ioctl.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 107c5f4..89f346c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1382,9 +1382,8 @@ static noinline int btrfs_ioctl_resize(struct file *file,
 
 	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
 			1)) {
-		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
 		mnt_drop_write_file(file);
-		return -EINVAL;
+		return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 	}
 
 	mutex_lock(&root->fs_info->volume_mutex);
@@ -2346,8 +2345,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
 
 	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
 			1)) {
-		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
-		return -EINVAL;
+		return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 	}
 
 	mutex_lock(&root->fs_info->volume_mutex);
@@ -3638,8 +3636,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root *root, void __user *arg)
 		if (atomic_xchg(
 			&root->fs_info->mutually_exclusive_operation_running,
 			1)) {
-			pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
-			ret = -EINPROGRESS;
+			ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 		} else {
 			ret = btrfs_dev_replace_start(root, p);
 			atomic_set(
@@ -3883,8 +3880,7 @@ again:
 	} else {
 		/* this is (1) */
 		mutex_unlock(&fs_info->balance_mutex);
-		pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
-		ret = -EINVAL;
+		ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 		goto out;
 	}
 
-- 
1.7.1


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

* Re: [PATCH] btrfs: return btrfs error code for dev excl ops err
  2013-08-20 18:34   ` Josef Bacik
@ 2013-08-21  3:47     ` Anand Jain
  2013-09-02 16:59     ` David Sterba
  1 sibling, 0 replies; 9+ messages in thread
From: Anand Jain @ 2013-08-21  3:47 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs




>> -			return "add/delete/balance/replace/resize operation "\
>> -				"in progress";
>> +			return "add/delete/balance/replace/resize operation in progress";
>>   		default:
>>   			return NULL;
>
> This is an unnecessary change.  Thanks,

  Hmm. ok. v2 sent out.



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

* [PATCH] btrfs-progs: use btrfs error code for kernel errors
  2013-08-16 12:52 [PATCH] btrfs-progs: mkfs should check for small vol well before Anand Jain
@ 2013-08-30  8:42 ` Anand Jain
  0 siblings, 0 replies; 9+ messages in thread
From: Anand Jain @ 2013-08-30  8:42 UTC (permalink / raw)
  To: linux-btrfs

Now with the below kernel patch, the excl operations like dev
add/replace/resize and balance returns the btrfs error
code defined in btrfs.h, this patch will help btrfs-progs
(and thus user) to know the error string on the terminal
(instead of /var/log/messages as previously kernel did).

This patch depends on the btrfs kernel patch:
  btrfs: return btrfs error code for dev excl ops err

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-balance.c    |   15 +++++++++++++++
 cmds-device.c     |    7 ++++++-
 cmds-filesystem.c |    6 +++++-
 cmds-replace.c    |    7 ++++++-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/cmds-balance.c b/cmds-balance.c
index c78b726..30019be 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -316,6 +316,12 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 			if (ret == 0)
 				goto out;
 			e = errno;
+			if (ret > 0) {
+				fprintf(stderr,
+					"ERROR: Balance failed due to - %s\n",
+					btrfs_err_str(ret));
+				goto out;
+			}
 		}
 
 		if (e == ECANCELED) {
@@ -332,6 +338,11 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 					"syslog - try dmesg | tail\n");
 			ret = 19;
 		}
+	} else if (ret > 0) {
+		fprintf(stderr,
+			"ERROR: Balance start failed - %s\n",
+			btrfs_err_str(ret));
+		ret = 1;
 	} else {
 		printf("Done, had to relocate %llu out of %llu chunks\n",
 		       (unsigned long long)args->stat.completed,
@@ -603,6 +614,10 @@ static int cmd_balance_resume(int argc, char **argv)
 "There may be more info in syslog - try dmesg | tail\n", path, strerror(e));
 			return 19;
 		}
+	} else if (ret > 0) {
+		fprintf(stderr,
+			"ERROR: Balance resume failed - %s\n",
+			btrfs_err_str(ret));
 	} else {
 		printf("Done, had to relocate %llu out of %llu chunks\n",
 		       (unsigned long long)args.stat.completed,
diff --git a/cmds-device.c b/cmds-device.c
index 833ad30..282590c 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -120,10 +120,15 @@ static int cmd_add_dev(int argc, char **argv)
 		strncpy_null(ioctl_args.name, argv[i]);
 		res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
 		e = errno;
-		if(res<0){
+		if (res < 0) {
 			fprintf(stderr, "ERROR: error adding the device '%s' - %s\n",
 				argv[i], strerror(e));
 			ret++;
+		} else if (res > 0) {
+			fprintf(stderr,
+				"ERROR: adding the device '%s' - %s\n",
+				argv[i], btrfs_err_str(res));
+			ret = 1;
 		}
 
 	}
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 412f793..2f6a0ab 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -577,10 +577,14 @@ static int cmd_resize(int argc, char **argv)
 	res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
 	e = errno;
 	close_file_or_dir(fd, dirstream);
-	if( res < 0 ){
+	if (res < 0) {
 		fprintf(stderr, "ERROR: unable to resize '%s' - %s\n", 
 			path, strerror(e));
 		return 30;
+	} else if (res > 0) {
+		fprintf(stderr, "ERROR: resize failed - %s\n",
+			btrfs_err_str(res));
+		return res;
 	}
 	return 0;
 }
diff --git a/cmds-replace.c b/cmds-replace.c
index 8ed92c4..e3ff695 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -297,12 +297,17 @@ static int cmd_start_replace(int argc, char **argv)
 	start_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_START;
 	ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args);
 	if (do_not_background) {
-		if (ret) {
+		if (ret < 0) {
 			fprintf(stderr,
 				"ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %s, %s\n",
 				path, strerror(errno),
 				replace_dev_result2string(start_args.result));
 			goto leave_with_error;
+		} else if (ret > 0) {
+			fprintf(stderr,
+				"ERROR: replace start failed on %s - %s\n",
+				path, btrfs_err_str(ret));
+			goto leave_with_error;
 		}
 
 		if (start_args.result !=
-- 
1.7.1


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

* Re: [PATCH] btrfs: return btrfs error code for dev excl ops err
  2013-08-20 18:34   ` Josef Bacik
  2013-08-21  3:47     ` Anand Jain
@ 2013-09-02 16:59     ` David Sterba
  1 sibling, 0 replies; 9+ messages in thread
From: David Sterba @ 2013-09-02 16:59 UTC (permalink / raw)
  To: Josef Bacik; +Cc: Anand Jain, linux-btrfs

On Tue, Aug 20, 2013 at 02:34:05PM -0400, Josef Bacik wrote:
> > --- a/include/uapi/linux/btrfs.h
> > +++ b/include/uapi/linux/btrfs.h
> > @@ -505,8 +505,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
> >  		case BTRFS_ERROR_DEV_ONLY_WRITABLE:
> >  			return "unable to remove the only writeable device";
> >  		case BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS:
> > -			return "add/delete/balance/replace/resize operation "\
> > -				"in progress";
> > +			return "add/delete/balance/replace/resize operation in progress";
> >  		default:
> >  			return NULL;
> 
> This is an unnecessary change.  Thanks,

Though having the whole message on one line makes errors greppable.

david

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

* [PATCH 3/3] btrfs-progs: use btrfs error code for kernel errors
  2013-08-20  6:10 [PATCH] btrfs-progs: use btrfs error code for kernel errors Anand Jain
  2013-08-20  6:10 ` [PATCH] btrfs: return btrfs error code for dev excl ops err Anand Jain
@ 2013-09-06  9:38 ` Anand Jain
  2013-09-13 11:35 ` [PATCH] " Anand Jain
  2 siblings, 0 replies; 9+ messages in thread
From: Anand Jain @ 2013-09-06  9:38 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Now with the below kernel patch, the excl operations like dev
add/replace/resize and balance returns the btrfs error
code defined in btrfs.h, this patch will help btrfs-progs
(and thus user) to know the error string on the terminal
(instead of /var/log/messages as previously kernel did).

This patch depends on the btrfs kernel patch:
  btrfs: return btrfs error code for dev excl ops err

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-balance.c    |   15 +++++++++++++++
 cmds-device.c     |    7 ++++++-
 cmds-filesystem.c |    6 +++++-
 cmds-replace.c    |    7 ++++++-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/cmds-balance.c b/cmds-balance.c
index b7382ef..4407a13 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -316,6 +316,12 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 			if (ret == 0)
 				goto out;
 			e = errno;
+			if (ret > 0) {
+				fprintf(stderr,
+					"ERROR: Balance failed due to - %s\n",
+					btrfs_err_str(ret));
+				goto out;
+			}
 		}
 
 		if (e == ECANCELED) {
@@ -332,6 +338,11 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 					"syslog - try dmesg | tail\n");
 			ret = 19;
 		}
+	} else if (ret > 0) {
+		fprintf(stderr,
+			"ERROR: Balance start failed - %s\n",
+			btrfs_err_str(ret));
+		ret = 1;
 	} else {
 		printf("Done, had to relocate %llu out of %llu chunks\n",
 		       (unsigned long long)args->stat.completed,
@@ -603,6 +614,10 @@ static int cmd_balance_resume(int argc, char **argv)
 "There may be more info in syslog - try dmesg | tail\n", path, strerror(e));
 			return 19;
 		}
+	} else if (ret > 0) {
+		fprintf(stderr,
+			"ERROR: Balance resume failed - %s\n",
+			btrfs_err_str(ret));
 	} else {
 		printf("Done, had to relocate %llu out of %llu chunks\n",
 		       (unsigned long long)args.stat.completed,
diff --git a/cmds-device.c b/cmds-device.c
index f3d4b67..bad4e15 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -111,10 +111,15 @@ static int cmd_add_dev(int argc, char **argv)
 		strncpy_null(ioctl_args.name, argv[i]);
 		res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
 		e = errno;
-		if(res<0){
+		if (res < 0) {
 			fprintf(stderr, "ERROR: error adding the device '%s' - %s\n",
 				argv[i], strerror(e));
 			ret++;
+		} else if (res > 0) {
+			fprintf(stderr,
+				"ERROR: adding the device '%s' - %s\n",
+				argv[i], btrfs_err_str(res));
+			ret = 1;
 		}
 
 	}
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 21f2096..2cf2228 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -577,10 +577,14 @@ static int cmd_resize(int argc, char **argv)
 	res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
 	e = errno;
 	close_file_or_dir(fd, dirstream);
-	if( res < 0 ){
+	if (res < 0) {
 		fprintf(stderr, "ERROR: unable to resize '%s' - %s\n", 
 			path, strerror(e));
 		return 30;
+	} else if (res > 0) {
+		fprintf(stderr, "ERROR: resize failed - %s\n",
+			btrfs_err_str(res));
+		return res;
 	}
 	return 0;
 }
diff --git a/cmds-replace.c b/cmds-replace.c
index 1df719b..e89f8cc 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -297,12 +297,17 @@ static int cmd_start_replace(int argc, char **argv)
 	start_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_START;
 	ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args);
 	if (do_not_background) {
-		if (ret) {
+		if (ret < 0) {
 			fprintf(stderr,
 				"ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %s, %s\n",
 				path, strerror(errno),
 				replace_dev_result2string(start_args.result));
 			goto leave_with_error;
+		} else if (ret > 0) {
+			fprintf(stderr,
+				"ERROR: replace start failed on %s - %s\n",
+				path, btrfs_err_str(ret));
+			goto leave_with_error;
 		}
 
 		if (start_args.result !=
-- 
1.7.1


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

* [PATCH] btrfs-progs: use btrfs error code for kernel errors
  2013-08-20  6:10 [PATCH] btrfs-progs: use btrfs error code for kernel errors Anand Jain
  2013-08-20  6:10 ` [PATCH] btrfs: return btrfs error code for dev excl ops err Anand Jain
  2013-09-06  9:38 ` [PATCH 3/3] btrfs-progs: use btrfs error code for kernel errors Anand Jain
@ 2013-09-13 11:35 ` Anand Jain
  2 siblings, 0 replies; 9+ messages in thread
From: Anand Jain @ 2013-09-13 11:35 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Now with the below kernel patch, the excl operations like dev
add/replace/resize and balance returns the btrfs error
code defined in btrfs.h, this patch will help btrfs-progs
(and thus user) to know the error string on the terminal
(instead of /var/log/messages as previously kernel did).

This patch depends on the btrfs kernel patch:
  btrfs: return btrfs error code for dev excl ops err

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-balance.c    | 15 +++++++++++++++
 cmds-device.c     |  7 ++++++-
 cmds-filesystem.c |  6 +++++-
 cmds-replace.c    |  7 ++++++-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/cmds-balance.c b/cmds-balance.c
index b7382ef..4407a13 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -316,6 +316,12 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 			if (ret == 0)
 				goto out;
 			e = errno;
+			if (ret > 0) {
+				fprintf(stderr,
+					"ERROR: Balance failed due to - %s\n",
+					btrfs_err_str(ret));
+				goto out;
+			}
 		}
 
 		if (e == ECANCELED) {
@@ -332,6 +338,11 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 					"syslog - try dmesg | tail\n");
 			ret = 19;
 		}
+	} else if (ret > 0) {
+		fprintf(stderr,
+			"ERROR: Balance start failed - %s\n",
+			btrfs_err_str(ret));
+		ret = 1;
 	} else {
 		printf("Done, had to relocate %llu out of %llu chunks\n",
 		       (unsigned long long)args->stat.completed,
@@ -603,6 +614,10 @@ static int cmd_balance_resume(int argc, char **argv)
 "There may be more info in syslog - try dmesg | tail\n", path, strerror(e));
 			return 19;
 		}
+	} else if (ret > 0) {
+		fprintf(stderr,
+			"ERROR: Balance resume failed - %s\n",
+			btrfs_err_str(ret));
 	} else {
 		printf("Done, had to relocate %llu out of %llu chunks\n",
 		       (unsigned long long)args.stat.completed,
diff --git a/cmds-device.c b/cmds-device.c
index e45fb1f..17ee7dd 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -111,10 +111,15 @@ static int cmd_add_dev(int argc, char **argv)
 		strncpy_null(ioctl_args.name, argv[i]);
 		res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
 		e = errno;
-		if(res<0){
+		if (res < 0) {
 			fprintf(stderr, "ERROR: error adding the device '%s' - %s\n",
 				argv[i], strerror(e));
 			ret++;
+		} else if (res > 0) {
+			fprintf(stderr,
+				"ERROR: adding the device '%s' - %s\n",
+				argv[i], btrfs_err_str(res));
+			ret = 1;
 		}
 
 	}
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index fa9d36b..b109416 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -618,10 +618,14 @@ static int cmd_resize(int argc, char **argv)
 	res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
 	e = errno;
 	close_file_or_dir(fd, dirstream);
-	if( res < 0 ){
+	if (res < 0) {
 		fprintf(stderr, "ERROR: unable to resize '%s' - %s\n", 
 			path, strerror(e));
 		return 1;
+	} else if (res > 0) {
+		fprintf(stderr, "ERROR: resize failed - %s\n",
+			btrfs_err_str(res));
+		return 1;
 	}
 	return 0;
 }
diff --git a/cmds-replace.c b/cmds-replace.c
index d9b0940..a31d77e 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -297,12 +297,17 @@ static int cmd_start_replace(int argc, char **argv)
 	start_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_START;
 	ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args);
 	if (do_not_background) {
-		if (ret) {
+		if (ret < 0) {
 			fprintf(stderr,
 				"ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %s, %s\n",
 				path, strerror(errno),
 				replace_dev_result2string(start_args.result));
 			goto leave_with_error;
+		} else if (ret > 0) {
+			fprintf(stderr,
+				"ERROR: replace start failed on %s - %s\n",
+				path, btrfs_err_str(ret));
+			goto leave_with_error;
 		}
 
 		if (start_args.result !=
-- 
1.8.4.rc4.1.g0d8beaa


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

end of thread, other threads:[~2013-09-13 11:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-20  6:10 [PATCH] btrfs-progs: use btrfs error code for kernel errors Anand Jain
2013-08-20  6:10 ` [PATCH] btrfs: return btrfs error code for dev excl ops err Anand Jain
2013-08-20 18:34   ` Josef Bacik
2013-08-21  3:47     ` Anand Jain
2013-09-02 16:59     ` David Sterba
2013-08-21  3:44   ` [PATCH v2] " Anand Jain
2013-09-06  9:38 ` [PATCH 3/3] btrfs-progs: use btrfs error code for kernel errors Anand Jain
2013-09-13 11:35 ` [PATCH] " Anand Jain
  -- strict thread matches above, loose matches on Subject: below --
2013-08-16 12:52 [PATCH] btrfs-progs: mkfs should check for small vol well before Anand Jain
2013-08-30  8:42 ` [PATCH] btrfs-progs: use btrfs error code for kernel errors Anand Jain

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