linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH v2 08/20] btrfs-progs: sub list: factor out main part of btrfs_list_subvols
Date: Mon, 18 Jun 2018 17:40:56 +0900	[thread overview]
Message-ID: <a1f7638d0335e3823f453d50c388500c01c6aa1d.1529310485.git.misono.tomohiro@jp.fujitsu.com> (raw)
In-Reply-To: <cover.1529310485.git.misono.tomohiro@jp.fujitsu.com>

No functional changes.
This is a preparation work for reworking "subvolume list".

Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
---
 cmds-subvolume.c | 50 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index c54a8003..279a6e51 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -1125,22 +1125,15 @@ out:
 	return subvols;
 }
 
-static struct subvol_list *btrfs_list_subvols(int fd,
-					      struct btrfs_list_filter_set_v2 *filter_set)
+static void get_subvols_info(struct subvol_list **subvols,
+			     struct btrfs_list_filter_set_v2 *filter_set,
+			     int fd,
+			     size_t *capacity)
 {
-	struct subvol_list *subvols;
-	size_t capacity = 0;
 	struct btrfs_util_subvolume_iterator *iter;
 	enum btrfs_util_error err;
 	int ret = -1;
 
-	subvols = malloc(sizeof(*subvols));
-	if (!subvols) {
-		error("out of memory");
-		return NULL;
-	}
-	subvols->num = 0;
-
 	err = btrfs_util_create_subvolume_iterator_fd(fd,
 						      BTRFS_FS_TREE_OBJECTID, 0,
 						      &iter);
@@ -1168,11 +1161,11 @@ static struct subvol_list *btrfs_list_subvols(int fd,
 			continue;
 		}
 
-		if (subvols->num >= capacity) {
+		if ((*subvols)->num >= *capacity) {
 			struct subvol_list *new_subvols;
-			size_t new_capacity = max_t(size_t, 1, capacity * 2);
+			size_t new_capacity = max_t(size_t, 1, *capacity * 2);
 
-			new_subvols = realloc(subvols,
+			new_subvols = realloc(*subvols,
 					      sizeof(*new_subvols) +
 					      new_capacity *
 					      sizeof(new_subvols->subvols[0]));
@@ -1181,12 +1174,12 @@ static struct subvol_list *btrfs_list_subvols(int fd,
 				goto out;
 			}
 
-			subvols = new_subvols;
-			capacity = new_capacity;
+			*subvols = new_subvols;
+			*capacity = new_capacity;
 		}
 
-		subvols->subvols[subvols->num] = subvol;
-		subvols->num++;
+		(*subvols)->subvols[(*subvols)->num] = subvol;
+		(*subvols)->num++;
 	}
 
 	ret = 0;
@@ -1194,9 +1187,26 @@ out:
 	if (iter)
 		btrfs_util_destroy_subvolume_iterator(iter);
 	if (ret) {
-		free_subvol_list(subvols);
-		subvols = NULL;
+		free_subvol_list(*subvols);
+		*subvols = NULL;
+	}
+}
+
+static struct subvol_list *btrfs_list_subvols(int fd,
+					      struct btrfs_list_filter_set_v2 *filter_set)
+{
+	struct subvol_list *subvols;
+	size_t capacity = 0;
+
+	subvols = malloc(sizeof(*subvols));
+	if (!subvols) {
+		error("out of memory");
+		return NULL;
 	}
+	subvols->num = 0;
+
+	get_subvols_info(&subvols, filter_set, fd, &capacity);
+
 	return subvols;
 }
 
-- 
2.14.4



  parent reply	other threads:[~2018-06-18  8:38 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-18  8:40 [PATCH v2 00/20] btrfs-progs: Rework of "subvolume list/show" and relax the root privileges of them Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 01/20] btrfs-progs: doc: Update man btrfs subvolume Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 02/20] btrfs-progs: ioctl/libbtrfsutil: Add 3 definitions of new unprivileged ioctl Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 03/20] btrfs-progs: libbtrfsutil: Factor out btrfs_util_subvolume_info_fd() Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 04/20] btrfs-porgs: libbtrfsutil: Relax the privileges of util_subvolume_info() Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 05/20] btrfs-progs: libbtrfsuitl: Factor out btrfs_util_subvolume_iterator_next() Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 06/20] btrfs-progs: libbtrfsutil: Relax the privileges of subvolume iterator Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 07/20] btrfs-progs: sub list: Use libbtrfsuitl for subvolume list Misono Tomohiro
2018-06-18  8:40 ` Misono Tomohiro [this message]
2018-06-18  8:40 ` [PATCH v2 09/20] btrfs-progs: sub list: Change the default behavior of "subvolume list" and allow non-privileged user to call it Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 10/20] btrfs-progs: sub list: Add -A option to output path in absolute path Misono Tomohiro
2018-06-18  8:40 ` [PATCH v2 11/20] btrfs-progs: sub list: Add -f option to follow mounted subvolumes below the path Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 12/20] btrfs-progs: sub list: Add --nosort option to output incrementally without sort Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 13/20] btrfs-progs: sub list: Update -a option and remove meaningless filter Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 14/20] btrfs-progs: sub list: Update help message of -o option Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 15/20] btrfs-progs: sub list: Update help message of -d option Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 16/20] btrfs-progs: utils: Fallback to open without O_NOATIME flag in find_mount_root(): Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 17/20] btrfs-progs: sub show: Allow non-privileged user to call "subvolume show" Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 18/20] btrfs-progs: test: Add helper function to check if test user exists Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 19/20] btrfs-porgs: test: Add cli-test/009 to check subvolume list for both root and normal user Misono Tomohiro
2018-06-18  8:41 ` [PATCH v2 20/20] btrfs-progs: test: Add cli-test/010 to check "subvolume list -f" option Misono Tomohiro
2018-07-04  8:14 ` [PATCH v2 00/20] btrfs-progs: Rework of "subvolume list/show" and relax the root privileges of them Misono Tomohiro
2018-08-03 13:46   ` David Sterba
2018-08-09  8:21     ` Misono Tomohiro
2018-08-15 18:12 ` David Sterba
2018-08-21  7:02   ` Misono Tomohiro

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=a1f7638d0335e3823f453d50c388500c01c6aa1d.1529310485.git.misono.tomohiro@jp.fujitsu.com \
    --to=misono.tomohiro@jp.fujitsu.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).