[5/5] btrfs-progs: mkfs: print error messages instead of just error number
diff mbox series

Message ID 20190814010402.22546-5-jeffm@suse.com
State New
Headers show
Series
  • [1/5] btrfs-progs: mkfs: treat btrfs_add_to_fsid as fatal error
Related show

Commit Message

Jeff Mahoney Aug. 14, 2019, 1:04 a.m. UTC
Printing the error number means having to go look up what that error
number means.  For a developer, it's easy.  For a user, it's unhelpful.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 mkfs/main.c | 47 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 17 deletions(-)

Comments

Qu Wenruo Aug. 14, 2019, 1:54 a.m. UTC | #1
On 2019/8/14 上午9:04, Jeff Mahoney wrote:
> Printing the error number means having to go look up what that error
> number means.  For a developer, it's easy.  For a user, it's unhelpful.
> 
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> ---
>  mkfs/main.c | 47 ++++++++++++++++++++++++++++++-----------------
>  1 file changed, 30 insertions(+), 17 deletions(-)
> 
> diff --git a/mkfs/main.c b/mkfs/main.c
> index b752da13..7bfeb610 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -1197,37 +1197,43 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>  
>  	ret = create_metadata_block_groups(root, mixed, &allocation);
>  	if (ret) {
> -		error("failed to create default block groups: %d", ret);
> +		error("failed to create default block groups: %d/%s",
> +		      ret, strerror(-ret));

The new trend is to use %m.

So we would do something like:
	errno = -ret;
	error("%m");

Thanks,
Qu

>  		goto error;
>  	}
>  
>  	trans = btrfs_start_transaction(root, 1);
>  	if (IS_ERR(trans)) {
> -		error("failed to start transaction");
> +		error("failed to start transaction: %ld/%s",
> +		      PTR_ERR(trans), strerror(-PTR_ERR(trans)));
>  		goto error;
>  	}
>  
>  	ret = create_data_block_groups(trans, root, mixed, &allocation);
>  	if (ret) {
> -		error("failed to create default data block groups: %d", ret);
> +		error("failed to create default data block groups: %d/%s",
> +		      ret, strerror(-ret));
>  		goto error;
>  	}
>  
>  	ret = make_root_dir(trans, root);
>  	if (ret) {
> -		error("failed to setup the root directory: %d", ret);
> +		error("failed to setup the root directory: %d/%s",
> +		      ret, strerror(-ret));
>  		goto error;
>  	}
>  
>  	ret = btrfs_commit_transaction(trans, root);
>  	if (ret) {
> -		error("unable to commit transaction: %d", ret);
> +		error("unable to commit transaction: %d/%s",
> +		      ret, strerror(-ret));
>  		goto out;
>  	}
>  
>  	trans = btrfs_start_transaction(root, 1);
>  	if (IS_ERR(trans)) {
> -		error("failed to start transaction");
> +		error("failed to start transaction: %ld/%s",
> +		      PTR_ERR(trans), strerror(-PTR_ERR(trans)));
>  		goto error;
>  	}
>  
> @@ -1267,7 +1273,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>  		ret = btrfs_add_to_fsid(trans, root, fd, file, dev_block_count,
>  					sectorsize, sectorsize, sectorsize);
>  		if (ret) {
> -			error("unable to add %s to filesystem: %d", file, ret);
> +			error("unable to add %s to filesystem: %d/%s", file, ret, strerror(-ret));
>  			goto error;
>  		}
>  		if (verbose >= 2) {
> @@ -1284,46 +1290,52 @@ raid_groups:
>  	ret = create_raid_groups(trans, root, data_profile,
>  			 metadata_profile, mixed, &allocation);
>  	if (ret) {
> -		error("unable to create raid groups: %d", ret);
> +		error("unable to create raid groups: %d/%s",
> +		      ret, strerror(-ret));
>  		goto out;
>  	}
>  
>  	ret = create_data_reloc_tree(trans);
>  	if (ret) {
> -		error("unable to create data reloc tree: %d", ret);
> +		error("unable to create data reloc tree: %d/%s",
> +		      ret, strerror(-ret));
>  		goto out;
>  	}
>  
>  	ret = create_uuid_tree(trans);
>  	if (ret)
>  		warning(
> -	"unable to create uuid tree, will be created after mount: %d", ret);
> +	"unable to create uuid tree, will be created after mount: %d/%s",
> +			ret, strerror(-ret));
>  
>  	ret = btrfs_commit_transaction(trans, root);
>  	if (ret) {
> -		error("unable to commit transaction: %d", ret);
> +		error("unable to commit transaction: %d/%s",
> +		      ret, strerror(-ret));
>  		goto out;
>  	}
>  
>  	ret = cleanup_temp_chunks(fs_info, &allocation, data_profile,
>  				  metadata_profile, metadata_profile);
>  	if (ret < 0) {
> -		error("failed to cleanup temporary chunks: %d", ret);
> +		error("failed to cleanup temporary chunks: %d/%s",
> +		      ret, strerror(-ret));
>  		goto out;
>  	}
>  
>  	if (source_dir_set) {
>  		ret = btrfs_mkfs_fill_dir(source_dir, root, verbose);
>  		if (ret) {
> -			error("error while filling filesystem: %d", ret);
> +			error("error while filling filesystem: %d/%s",
> +			      ret, strerror(-ret));
>  			goto out;
>  		}
>  		if (shrink_rootdir) {
>  			ret = btrfs_mkfs_shrink_fs(fs_info, &shrink_size,
>  						   shrink_rootdir);
>  			if (ret < 0) {
> -				error("error while shrinking filesystem: %d",
> -					ret);
> +				error("error while shrinking filesystem: %d/%s",
> +					ret, strerror(-ret));
>  				goto out;
>  			}
>  		}
> @@ -1383,8 +1395,9 @@ out:
>  
>  	if (!ret && close_ret) {
>  		ret = close_ret;
> -		error("failed to close ctree, the filesystem may be inconsistent: %d",
> -		      ret);
> +		error(
> +	"failed to close ctree, the filesystem may be inconsistent: %d/%s",
> +		      ret, strerror(-ret));
>  	}
>  
>  	btrfs_close_all_devices();
>
Jeff Mahoney Aug. 14, 2019, 2:30 a.m. UTC | #2
> On Aug 13, 2019, at 9:54 PM, Qu Wenruo <quwenruo.btrfs@gmx.com> wrote:
> 
> 
> 
>> On 2019/8/14 上午9:04, Jeff Mahoney wrote:
>> Printing the error number means having to go look up what that error
>> number means.  For a developer, it's easy.  For a user, it's unhelpful.
>> 
>> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
>> ---
>> mkfs/main.c | 47 ++++++++++++++++++++++++++++++-----------------
>> 1 file changed, 30 insertions(+), 17 deletions(-)
>> 
>> diff --git a/mkfs/main.c b/mkfs/main.c
>> index b752da13..7bfeb610 100644
>> --- a/mkfs/main.c
>> +++ b/mkfs/main.c
>> @@ -1197,37 +1197,43 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>> 
>>    ret = create_metadata_block_groups(root, mixed, &allocation);
>>    if (ret) {
>> -        error("failed to create default block groups: %d", ret);
>> +        error("failed to create default block groups: %d/%s",
>> +              ret, strerror(-ret));
> 
> The new trend is to use %m.
> 
> So we would do something like:
>    errno = -ret;
>    error("%m");
> 

Ok. It seems like that’s a job for a macro to set errno and autoappend the error message. I have a local branch that does that already.

-Jeff


> Thanks,
> Qu
> 
>>        goto error;
>>    }
>> 
>>    trans = btrfs_start_transaction(root, 1);
>>    if (IS_ERR(trans)) {
>> -        error("failed to start transaction");
>> +        error("failed to start transaction: %ld/%s",
>> +              PTR_ERR(trans), strerror(-PTR_ERR(trans)));
>>        goto error;
>>    }
>> 
>>    ret = create_data_block_groups(trans, root, mixed, &allocation);
>>    if (ret) {
>> -        error("failed to create default data block groups: %d", ret);
>> +        error("failed to create default data block groups: %d/%s",
>> +              ret, strerror(-ret));
>>        goto error;
>>    }
>> 
>>    ret = make_root_dir(trans, root);
>>    if (ret) {
>> -        error("failed to setup the root directory: %d", ret);
>> +        error("failed to setup the root directory: %d/%s",
>> +              ret, strerror(-ret));
>>        goto error;
>>    }
>> 
>>    ret = btrfs_commit_transaction(trans, root);
>>    if (ret) {
>> -        error("unable to commit transaction: %d", ret);
>> +        error("unable to commit transaction: %d/%s",
>> +              ret, strerror(-ret));
>>        goto out;
>>    }
>> 
>>    trans = btrfs_start_transaction(root, 1);
>>    if (IS_ERR(trans)) {
>> -        error("failed to start transaction");
>> +        error("failed to start transaction: %ld/%s",
>> +              PTR_ERR(trans), strerror(-PTR_ERR(trans)));
>>        goto error;
>>    }
>> 
>> @@ -1267,7 +1273,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>>        ret = btrfs_add_to_fsid(trans, root, fd, file, dev_block_count,
>>                    sectorsize, sectorsize, sectorsize);
>>        if (ret) {
>> -            error("unable to add %s to filesystem: %d", file, ret);
>> +            error("unable to add %s to filesystem: %d/%s", file, ret, strerror(-ret));
>>            goto error;
>>        }
>>        if (verbose >= 2) {
>> @@ -1284,46 +1290,52 @@ raid_groups:
>>    ret = create_raid_groups(trans, root, data_profile,
>>             metadata_profile, mixed, &allocation);
>>    if (ret) {
>> -        error("unable to create raid groups: %d", ret);
>> +        error("unable to create raid groups: %d/%s",
>> +              ret, strerror(-ret));
>>        goto out;
>>    }
>> 
>>    ret = create_data_reloc_tree(trans);
>>    if (ret) {
>> -        error("unable to create data reloc tree: %d", ret);
>> +        error("unable to create data reloc tree: %d/%s",
>> +              ret, strerror(-ret));
>>        goto out;
>>    }
>> 
>>    ret = create_uuid_tree(trans);
>>    if (ret)
>>        warning(
>> -    "unable to create uuid tree, will be created after mount: %d", ret);
>> +    "unable to create uuid tree, will be created after mount: %d/%s",
>> +            ret, strerror(-ret));
>> 
>>    ret = btrfs_commit_transaction(trans, root);
>>    if (ret) {
>> -        error("unable to commit transaction: %d", ret);
>> +        error("unable to commit transaction: %d/%s",
>> +              ret, strerror(-ret));
>>        goto out;
>>    }
>> 
>>    ret = cleanup_temp_chunks(fs_info, &allocation, data_profile,
>>                  metadata_profile, metadata_profile);
>>    if (ret < 0) {
>> -        error("failed to cleanup temporary chunks: %d", ret);
>> +        error("failed to cleanup temporary chunks: %d/%s",
>> +              ret, strerror(-ret));
>>        goto out;
>>    }
>> 
>>    if (source_dir_set) {
>>        ret = btrfs_mkfs_fill_dir(source_dir, root, verbose);
>>        if (ret) {
>> -            error("error while filling filesystem: %d", ret);
>> +            error("error while filling filesystem: %d/%s",
>> +                  ret, strerror(-ret));
>>            goto out;
>>        }
>>        if (shrink_rootdir) {
>>            ret = btrfs_mkfs_shrink_fs(fs_info, &shrink_size,
>>                           shrink_rootdir);
>>            if (ret < 0) {
>> -                error("error while shrinking filesystem: %d",
>> -                    ret);
>> +                error("error while shrinking filesystem: %d/%s",
>> +                    ret, strerror(-ret));
>>                goto out;
>>            }
>>        }
>> @@ -1383,8 +1395,9 @@ out:
>> 
>>    if (!ret && close_ret) {
>>        ret = close_ret;
>> -        error("failed to close ctree, the filesystem may be inconsistent: %d",
>> -              ret);
>> +        error(
>> +    "failed to close ctree, the filesystem may be inconsistent: %d/%s",
>> +              ret, strerror(-ret));
>>    }
>> 
>>    btrfs_close_all_devices();
>> 
> 

--
Jeff Mahoney
SUSE Labs

Patch
diff mbox series

diff --git a/mkfs/main.c b/mkfs/main.c
index b752da13..7bfeb610 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1197,37 +1197,43 @@  int BOX_MAIN(mkfs)(int argc, char **argv)
 
 	ret = create_metadata_block_groups(root, mixed, &allocation);
 	if (ret) {
-		error("failed to create default block groups: %d", ret);
+		error("failed to create default block groups: %d/%s",
+		      ret, strerror(-ret));
 		goto error;
 	}
 
 	trans = btrfs_start_transaction(root, 1);
 	if (IS_ERR(trans)) {
-		error("failed to start transaction");
+		error("failed to start transaction: %ld/%s",
+		      PTR_ERR(trans), strerror(-PTR_ERR(trans)));
 		goto error;
 	}
 
 	ret = create_data_block_groups(trans, root, mixed, &allocation);
 	if (ret) {
-		error("failed to create default data block groups: %d", ret);
+		error("failed to create default data block groups: %d/%s",
+		      ret, strerror(-ret));
 		goto error;
 	}
 
 	ret = make_root_dir(trans, root);
 	if (ret) {
-		error("failed to setup the root directory: %d", ret);
+		error("failed to setup the root directory: %d/%s",
+		      ret, strerror(-ret));
 		goto error;
 	}
 
 	ret = btrfs_commit_transaction(trans, root);
 	if (ret) {
-		error("unable to commit transaction: %d", ret);
+		error("unable to commit transaction: %d/%s",
+		      ret, strerror(-ret));
 		goto out;
 	}
 
 	trans = btrfs_start_transaction(root, 1);
 	if (IS_ERR(trans)) {
-		error("failed to start transaction");
+		error("failed to start transaction: %ld/%s",
+		      PTR_ERR(trans), strerror(-PTR_ERR(trans)));
 		goto error;
 	}
 
@@ -1267,7 +1273,7 @@  int BOX_MAIN(mkfs)(int argc, char **argv)
 		ret = btrfs_add_to_fsid(trans, root, fd, file, dev_block_count,
 					sectorsize, sectorsize, sectorsize);
 		if (ret) {
-			error("unable to add %s to filesystem: %d", file, ret);
+			error("unable to add %s to filesystem: %d/%s", file, ret, strerror(-ret));
 			goto error;
 		}
 		if (verbose >= 2) {
@@ -1284,46 +1290,52 @@  raid_groups:
 	ret = create_raid_groups(trans, root, data_profile,
 			 metadata_profile, mixed, &allocation);
 	if (ret) {
-		error("unable to create raid groups: %d", ret);
+		error("unable to create raid groups: %d/%s",
+		      ret, strerror(-ret));
 		goto out;
 	}
 
 	ret = create_data_reloc_tree(trans);
 	if (ret) {
-		error("unable to create data reloc tree: %d", ret);
+		error("unable to create data reloc tree: %d/%s",
+		      ret, strerror(-ret));
 		goto out;
 	}
 
 	ret = create_uuid_tree(trans);
 	if (ret)
 		warning(
-	"unable to create uuid tree, will be created after mount: %d", ret);
+	"unable to create uuid tree, will be created after mount: %d/%s",
+			ret, strerror(-ret));
 
 	ret = btrfs_commit_transaction(trans, root);
 	if (ret) {
-		error("unable to commit transaction: %d", ret);
+		error("unable to commit transaction: %d/%s",
+		      ret, strerror(-ret));
 		goto out;
 	}
 
 	ret = cleanup_temp_chunks(fs_info, &allocation, data_profile,
 				  metadata_profile, metadata_profile);
 	if (ret < 0) {
-		error("failed to cleanup temporary chunks: %d", ret);
+		error("failed to cleanup temporary chunks: %d/%s",
+		      ret, strerror(-ret));
 		goto out;
 	}
 
 	if (source_dir_set) {
 		ret = btrfs_mkfs_fill_dir(source_dir, root, verbose);
 		if (ret) {
-			error("error while filling filesystem: %d", ret);
+			error("error while filling filesystem: %d/%s",
+			      ret, strerror(-ret));
 			goto out;
 		}
 		if (shrink_rootdir) {
 			ret = btrfs_mkfs_shrink_fs(fs_info, &shrink_size,
 						   shrink_rootdir);
 			if (ret < 0) {
-				error("error while shrinking filesystem: %d",
-					ret);
+				error("error while shrinking filesystem: %d/%s",
+					ret, strerror(-ret));
 				goto out;
 			}
 		}
@@ -1383,8 +1395,9 @@  out:
 
 	if (!ret && close_ret) {
 		ret = close_ret;
-		error("failed to close ctree, the filesystem may be inconsistent: %d",
-		      ret);
+		error(
+	"failed to close ctree, the filesystem may be inconsistent: %d/%s",
+		      ret, strerror(-ret));
 	}
 
 	btrfs_close_all_devices();