From: Eric Sandeen <sandeen@redhat.com>
To: linux-btrfs@vger.kernel.org
Cc: Eric Sandeen <sandeen@redhat.com>
Subject: [PATCH 04/17] btrfs-progs: btrfs_list_get_path_rootid error handling
Date: Mon, 25 Feb 2013 16:54:37 -0600 [thread overview]
Message-ID: <1361832890-40921-5-git-send-email-sandeen@redhat.com> (raw)
In-Reply-To: <1361832890-40921-1-git-send-email-sandeen@redhat.com>
btrfs_list_get_path_rootid() tries to return a negative
number on error, but it's a u64 function. Callers which test
for a return < 0 will never see an error.
Change the function to fill in the rootid via a pointer,
and then return a simple int as error.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
btrfs-list.c | 31 +++++++++++++++++++++++--------
btrfs-list.h | 2 +-
cmds-subvolume.c | 14 +++++++++-----
3 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/btrfs-list.c b/btrfs-list.c
index ab9179f..851c059 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1500,8 +1500,13 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
{
struct root_lookup root_lookup;
struct root_lookup root_sort;
- int ret;
- u64 top_id = (full_path ? 0 : btrfs_list_get_path_rootid(fd));
+ int ret = 0;
+ u64 top_id = 0;
+
+ if (full_path)
+ ret = btrfs_list_get_path_rootid(fd, &top_id);
+ if (ret)
+ return ret;
ret = btrfs_list_subvols(fd, &root_lookup);
if (ret)
@@ -1524,13 +1529,18 @@ char *strdup_or_null(const char *s)
int btrfs_get_subvol(int fd, struct root_info *the_ri)
{
- int ret = 1, rr;
+ int ret, rr;
struct root_lookup rl;
struct rb_node *rbn;
struct root_info *ri;
- u64 root_id = btrfs_list_get_path_rootid(fd);
+ u64 root_id;
+
+ ret = btrfs_list_get_path_rootid(fd, &root_id);
+ if (ret)
+ return ret;
- if (btrfs_list_subvols(fd, &rl))
+ ret = btrfs_list_subvols(fd, &rl);
+ if (ret)
return ret;
rbn = rb_first(&rl.root);
@@ -1741,7 +1751,11 @@ char *btrfs_list_path_for_root(int fd, u64 root)
struct rb_node *n;
char *ret_path = NULL;
int ret;
- u64 top_id = btrfs_list_get_path_rootid(fd);
+ u64 top_id;
+
+ ret = btrfs_list_get_path_rootid(fd, &top_id);
+ if (ret)
+ return ERR_PTR(ret);
ret = __list_subvol_search(fd, &root_lookup);
if (ret < 0)
@@ -1868,7 +1882,7 @@ int btrfs_list_parse_filter_string(char *optarg,
return 0;
}
-u64 btrfs_list_get_path_rootid(int fd)
+int btrfs_list_get_path_rootid(int fd, u64 *treeid)
{
int ret;
struct btrfs_ioctl_ino_lookup_args args;
@@ -1883,5 +1897,6 @@ u64 btrfs_list_get_path_rootid(int fd)
strerror(errno));
return ret;
}
- return args.treeid;
+ *treeid = args.treeid;
+ return 0;
}
diff --git a/btrfs-list.h b/btrfs-list.h
index 5d87454..2894451 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -156,5 +156,5 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
char *btrfs_list_path_for_root(int fd, u64 root);
-u64 btrfs_list_get_path_rootid(int fd);
+int btrfs_list_get_path_rootid(int fd, u64 *treeid);
int btrfs_get_subvol(int fd, struct root_info *the_ri);
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ea128fc..f9258fc 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -433,7 +433,11 @@ static int cmd_subvol_list(int argc, char **argv)
goto out;
}
- top_id = btrfs_list_get_path_rootid(fd);
+ ret = btrfs_list_get_path_rootid(fd, &top_id);
+ if (ret) {
+ fprintf(stderr, "ERROR: can't get rootid for '%s'\n", subvol);
+ goto out;
+ }
if (is_list_all)
btrfs_list_setup_filter(&filter_set,
@@ -821,8 +825,8 @@ static int cmd_subvol_show(int argc, char **argv)
goto out;
}
- sv_id = btrfs_list_get_path_rootid(fd);
- if (sv_id < 0) {
+ ret = btrfs_list_get_path_rootid(fd, &sv_id);
+ if (ret) {
fprintf(stderr, "ERROR: can't get rootid for '%s'\n",
fullpath);
goto out;
@@ -834,8 +838,8 @@ static int cmd_subvol_show(int argc, char **argv)
goto out;
}
- mntid = btrfs_list_get_path_rootid(mntfd);
- if (mntid < 0) {
+ ret = btrfs_list_get_path_rootid(mntfd, &mntid);
+ if (ret) {
fprintf(stderr, "ERROR: can't get rootid for '%s'\n", mnt);
goto out;
}
--
1.7.1
next prev parent reply other threads:[~2013-02-25 21:55 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 22:54 [PATCH 00/17] btrfs-progs: More misc fixes & cleanups Eric Sandeen
2013-02-25 22:54 ` [PATCH 01/17] btrfs-progs: Unify size-parsing Eric Sandeen
2013-02-25 23:26 ` Zach Brown
2013-02-25 23:37 ` Eric Sandeen
2013-02-26 0:26 ` Zach Brown
2013-02-26 18:50 ` Goffredo Baroncelli
2013-02-26 20:17 ` Eric Sandeen
2013-02-26 21:15 ` Goffredo Baroncelli
2013-02-25 22:54 ` [PATCH 02/17] btrfs-progs: fix btrfs_get_subvol cut/paste error Eric Sandeen
2013-02-25 22:54 ` [PATCH 03/17] btrfs-progs: Remove write-only var fdres in cmd_dev_stats() Eric Sandeen
2013-02-25 22:54 ` Eric Sandeen [this message]
2013-02-25 22:54 ` [PATCH 05/17] btrfs-progs: avoid double-free in __btrfs_map_block Eric Sandeen
2013-02-25 22:54 ` [PATCH 06/17] btrfs-progs: fix open error test in cmd_start_replace Eric Sandeen
2013-02-25 22:54 ` [PATCH 07/17] btrfs-progs: fix close of error fd in scrub cancel Eric Sandeen
2013-02-25 22:54 ` [PATCH 08/17] btrfs-progs: more scrub cancel error handling Eric Sandeen
2013-02-25 22:54 ` [PATCH 09/17] btrfs-progs: free memory before error exit in read_whole_eb Eric Sandeen
2013-02-25 22:54 ` [PATCH 10/17] btrfs-progs: don't call close on error fd Eric Sandeen
2013-02-25 22:54 ` [PATCH 11/17] btrfs-progs: provide positive errno to strerror in cmd_restore Eric Sandeen
2013-02-25 22:54 ` [PATCH 12/17] btrfs-progs: free allocated di_args in cmd_start_replace Eric Sandeen
2013-02-25 22:54 ` [PATCH 13/17] btrfs-progs: close fd on cmd_subvol_get_default return Eric Sandeen
2013-02-25 22:54 ` [PATCH 14/17] btrfs-progs: fix mem leak in resolve_root Eric Sandeen
2013-02-26 0:36 ` Shilong Wang
2013-02-26 4:36 ` Eric Sandeen
2013-02-27 13:03 ` David Sterba
2013-02-27 13:12 ` Shilong Wang
2013-02-25 22:54 ` [PATCH 15/17] btrfs-progs: Tidy up resolve_root Eric Sandeen
2013-02-25 22:54 ` [PATCH 16/17] btrfs-progs: fix fd leak in cmd_subvol_set_default Eric Sandeen
2013-02-26 18:46 ` Goffredo Baroncelli
2013-02-26 20:10 ` Eric Sandeen
2013-02-26 21:04 ` Goffredo Baroncelli
2013-02-27 12:38 ` David Sterba
2013-02-25 22:54 ` [PATCH 17/17] btrfs-progs: replace strtok_r with strsep Eric Sandeen
2013-02-26 18:47 ` Goffredo Baroncelli
2013-02-26 20:13 ` Eric Sandeen
2013-02-26 20:20 ` [PATCH 17/17 V2] " Eric Sandeen
2013-02-26 20:40 ` Ilya Dryomov
2013-02-26 20:46 ` Eric Sandeen
2013-02-26 21:07 ` Ilya Dryomov
2013-02-26 21:50 ` [PATCH 17/17 V3] btrfs-progs: initialize save_ptr prior to strtok_r Eric Sandeen
2013-02-27 13:54 ` [PATCH 00/17] btrfs-progs: More misc fixes & cleanups David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1361832890-40921-5-git-send-email-sandeen@redhat.com \
--to=sandeen@redhat.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).