summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2013-07-15 13:30:53 +0800
committerDavid Sterba <dsterba@suse.cz>2013-08-09 14:32:36 +0200
commitb8e23d4fb268152447761a9855d0afc75065215f (patch)
treecbfe0fa793eefffe9380ec958af01aa10754f946
parent5333445574adf8415ce3b7e8b13cf8feeb39b836 (diff)
btrfs-progs: device delete to get errors from the kernel
when user runs command btrfs dev del the raid requisite error if any goes to the /var/log/messages, its not good idea to clutter messages with these user (knowledge) errors, further user don't have to review the system messages to know problem with the cli it should be dropped to the user as part of the cli return. to bring this feature created a set of the ERROR defined BTRFS_ERROR_DEV* error codes and created their error string. I expect this enum to be added with other error which we might want to communicate to the user land Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r--cmds-device.c10
-rw-r--r--ioctl.h43
2 files changed, 50 insertions, 3 deletions
diff --git a/cmds-device.c b/cmds-device.c
index c1dc363a..be2aaff3 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -165,8 +165,14 @@ static int cmd_rm_dev(int argc, char **argv)
strncpy_null(arg.name, argv[i]);
res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
e = errno;
- if(res<0){
- fprintf(stderr, "ERROR: error removing the device '%s' - %s\n",
+ if (res > 0) {
+ fprintf(stderr,
+ "ERROR: error removing the device '%s' - %s\n",
+ argv[i], btrfs_err_str(res));
+ ret++;
+ } else if (res < 0) {
+ fprintf(stderr,
+ "ERROR: error removing the device '%s' - %s\n",
argv[i], strerror(e));
ret++;
}
diff --git a/ioctl.h b/ioctl.h
index f7864100..27521d5c 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -455,6 +455,48 @@ struct btrfs_ioctl_qgroup_create_args {
__u64 create;
__u64 qgroupid;
};
+
+/* Error codes as returned by the kernel */
+enum btrfs_err_code {
+ notused,
+ BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
+ BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
+ BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
+ BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
+ BTRFS_ERROR_DEV_TGT_REPLACE,
+ BTRFS_ERROR_DEV_MISSING_NOT_FOUND,
+ BTRFS_ERROR_DEV_ONLY_WRITABLE,
+ BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
+};
+
+/* An error code to error string mapping for the kernel
+* error codes
+*/
+static inline char *btrfs_err_str(enum btrfs_err_code err_code)
+{
+ switch (err_code) {
+ case BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET:
+ return "unable to go below two devices on raid1";
+ case BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET:
+ return "unable to go below four devices on raid10";
+ case BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET:
+ return "unable to go below two devices on raid5";
+ case BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET:
+ return "unable to go below three devices on raid6";
+ case BTRFS_ERROR_DEV_TGT_REPLACE:
+ return "unable to remove the dev_replace target dev";
+ case BTRFS_ERROR_DEV_MISSING_NOT_FOUND:
+ return "no missing devices found to remove";
+ 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";
+ default:
+ return NULL;
+ }
+}
+
#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
struct btrfs_ioctl_vol_args)
#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -550,7 +592,6 @@ struct btrfs_ioctl_clone_range_args {
struct btrfs_ioctl_get_dev_stats)
#define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
struct btrfs_ioctl_dev_replace_args)
-
#ifdef __cplusplus
}
#endif