diff mbox

[1/2] btrfs-progs: make get_btrfs_mount callable

Message ID 1382421202-18494-1-git-send-email-anand.jain@oracle.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Anand Jain Oct. 22, 2013, 5:53 a.m. UTC
get_btrfs_mount is reusable function but it is printing
errors, this removes it. Here the parent function of
open_path_or_dev_mnt does print error msg on error.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 utils.c |    6 ++----
 utils.h |    1 +
 2 files changed, 3 insertions(+), 4 deletions(-)

Comments

David Sterba Oct. 22, 2013, 2:43 p.m. UTC | #1
On Tue, Oct 22, 2013 at 01:53:21PM +0800, Anand Jain wrote:
> get_btrfs_mount is reusable function but it is printing
> errors, this removes it. Here the parent function of
> open_path_or_dev_mnt does print error msg on error.

Yeah, but then each caller should duplicate the is_block_device check to
keep get_btrfs_mount silent. There should be 2 functions, one that does
all the error checking and prints error messages and one that is silent
and usable eg. from a library. I'll keep the patch as-is for now because
there are no other users than open_path_or_dev_mnt and the function is
not exported to library.

david
--
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
Anand Jain Oct. 23, 2013, 2:11 a.m. UTC | #2
On 10/22/13 10:43 PM, David Sterba wrote:
> On Tue, Oct 22, 2013 at 01:53:21PM +0800, Anand Jain wrote:
>> get_btrfs_mount is reusable function but it is printing
>> errors, this removes it. Here the parent function of
>> open_path_or_dev_mnt does print error msg on error.
>
> Yeah, but then each caller should duplicate the is_block_device check to
> keep get_btrfs_mount silent. There should be 2 functions, one that does
> all the error checking and prints error messages and one that is silent
> and usable eg. from a library. I'll keep the patch as-is for now because
> there are no other users than open_path_or_dev_mnt and the function is
> not exported to library.

  yeah. sounds good. certainly we do have opportunities
  when we are on the lib functions.

Thanks, Anand
--
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
diff mbox

Patch

diff --git a/utils.c b/utils.c
index a7441c1..cb69b2b 100644
--- a/utils.c
+++ b/utils.c
@@ -692,7 +692,8 @@  int is_block_device(const char *path) {
  * On failure, returns -errno (not mounted yields -EINVAL)
  * Is noisy on failures, expects to be given a mounted device.
  */
-static int get_btrfs_mount(const char *dev, char *mp, size_t mp_size) {
+int get_btrfs_mount(const char *dev, char *mp, size_t mp_size)
+{
 	int ret;
 	int fd = -1;
 
@@ -717,7 +718,6 @@  static int get_btrfs_mount(const char *dev, char *mp, size_t mp_size) {
 
 	ret = check_mounted_where(fd, dev, mp, mp_size, NULL);
 	if (!ret) {
-		fprintf(stderr, "%s is not a mounted btrfs device\n", dev);
 		ret = -EINVAL;
 	} else { /* mounted, all good */
 		ret = 0;
@@ -725,8 +725,6 @@  static int get_btrfs_mount(const char *dev, char *mp, size_t mp_size) {
 out:
 	if (fd != -1)
 		close(fd);
-	if (ret)
-		fprintf(stderr, "Could not get mountpoint for %s\n", dev);
 	return ret;
 }
 
diff --git a/utils.h b/utils.h
index 251ef8e..8370686 100644
--- a/utils.h
+++ b/utils.h
@@ -91,5 +91,6 @@  int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
 int ask_user(char *question);
 int lookup_ino_rootid(int fd, u64 *rootid);
 int btrfs_scan_lblkid(int update_kernel);
+int get_btrfs_mount(const char *dev, char *mp, size_t mp_size);
 
 #endif