Skip to contentSkip to conversation

Remove unnecessary placeholder in btrfs_err_code

PATCH In review Satoru Takeuchi 3 participants 6 messages Dec 22, 2014 – Dec 29, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Remove unnecessary placeholder in btrfs_err_code

From: Satoru Takeuchi <[email protected]>

"notused" is not necessary. Set 1 to the first entry is enough.

---
 ioctl.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
ioctl.h +1 -2
index 2c2c7c1..c377b96 100644
@@ -474,8 +474,7 @@ struct btrfs_ioctl_qgroup_create_args {
 
 /* Error codes as returned by the kernel */
 enum btrfs_err_code {
-	notused,
-	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
+	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
 	BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
 	BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
 	BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/2 Capitalize elements in enum for improve readability.

From: Satoru Takeuchi <[email protected]>

There are 25 enums in btrfs-progs and only two of them use lower case letters for the name of elements. Capitalize them to readability.

---
 cmds-property.c | 18 +++++++++---------
 cmds-receive.c  |  6 +++---
 cmds-send.c     |  8 ++++----
 props.c         |  6 +++---
 props.h         | 10 +++++-----
 send-utils.c    | 50 +++++++++++++++++++++++++-------------------------
 send-utils.h    |  8 ++++----
 7 files changed, 53 insertions(+), 53 deletions(-)
cmds-property.c +9 -9
index a764293..b7c01b3 100644
@@ -197,19 +197,19 @@ static int autodetect_object_types(const char *object, int *types_out)
 	}
 
 	if (is_btrfs_object) {
-		types |= prop_object_inode;
+		types |= PROP_OBJECT_INODE;
 		if (st.st_ino == BTRFS_FIRST_FREE_OBJECTID)
-			types |= prop_object_subvol;
+			types |= PROP_OBJECT_SUBVOL;
 
 		ret = check_is_root(object);
 		if (ret < 0)
 			goto out;
 		if (!ret)
-			types |= prop_object_root;
+			types |= PROP_OBJECT_ROOT;
 	}
 
 	if (S_ISBLK(st.st_mode))
-		types |= prop_object_dev;
+		types |= PROP_OBJECT_DEV;
 
 	ret = 0;
 	*types_out = types;
@@ -250,7 +250,7 @@ static int dump_props(int types, const char *object, int name_and_help)
 
 	for (i = 0; prop_handlers[i].name; i++) {
 		prop = &prop_handlers[i];
-		for (j = 1; j < __prop_object_max; j <<= 1) {
+		for (j = 1; j < __PROP_OBJECT_MAX; j <<= 1) {
 			ret = dump_prop(prop, object, types, j, name_and_help);
 			if (ret < 0) {
 				ret = 50;
@@ -338,16 +338,16 @@ static void parse_args(int argc, char **argv,
 	*types = 0;
 	if (type_str) {
 		if (!strcmp(type_str, "s") || !strcmp(type_str, "subvol")) {
-			*types = prop_object_subvol;
+			*types = PROP_OBJECT_SUBVOL;
 		} else if (!strcmp(type_str, "f") ||
 			   !strcmp(type_str, "filesystem")) {
-			*types = prop_object_root;
+			*types = PROP_OBJECT_ROOT;
 		} else if (!strcmp(type_str, "i") ||
 			   !strcmp(type_str, "inode")) {
-			*types = prop_object_inode;
+			*types = PROP_OBJECT_INODE;
 		} else if (!strcmp(type_str, "d") ||
 			   !strcmp(type_str, "device")) {
-			*types = prop_object_dev;
+			*types = PROP_OBJECT_DEV;
 		} else {
 			fprintf(stderr, "ERROR: invalid object type.\n");
 			usage(usage_str);
cmds-receive.c +3 -3
index f269ade..caa79c0 100644
@@ -233,10 +233,10 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
 	strncpy_null(args_v2.name, path);
 
 	parent_subvol = subvol_uuid_search(&r->sus, 0, parent_uuid,
-			parent_ctransid, NULL, subvol_search_by_received_uuid);
+			parent_ctransid, NULL, SUBVOL_SEARCH_BY_RECEIVED_UUID);
 	if (!parent_subvol) {
 		parent_subvol = subvol_uuid_search(&r->sus, 0, parent_uuid,
-				parent_ctransid, NULL, subvol_search_by_uuid);
+				parent_ctransid, NULL, SUBVOL_SEARCH_BY_UUID);
 	}
 	if (!parent_subvol) {
 		ret = -ENOENT;
@@ -583,7 +583,7 @@ static int process_clone(const char *path, u64 offset, u64 len,
 		goto out;
 
 	si = subvol_uuid_search(&r->sus, 0, clone_uuid, clone_ctransid, NULL,
-			subvol_search_by_received_uuid);
+			SUBVOL_SEARCH_BY_RECEIVED_UUID);
 	if (!si) {
 		if (memcmp(clone_uuid, r->cur_subvol->received_uuid,
 				BTRFS_UUID_SIZE) == 0) {
cmds-send.c +4 -4
index 9b32c1f..730d0ea 100644
@@ -63,7 +63,7 @@ static int get_root_id(struct btrfs_send *s, const char *path, u64 *root_id)
 	struct subvol_info *si;
 
 	si = subvol_uuid_search(&s->sus, 0, NULL, 0, path,
-			subvol_search_by_path);
+			SUBVOL_SEARCH_BY_PATH);
 	if (!si)
 		return -ENOENT;
 	*root_id = si->root_id;
@@ -78,12 +78,12 @@ static struct subvol_info *get_parent(struct btrfs_send *s, u64 root_id)
 	struct subvol_info *si;
 
 	si_tmp = subvol_uuid_search(&s->sus, root_id, NULL, 0, NULL,
-			subvol_search_by_root_id);
+			SUBVOL_SEARCH_BY_ROOT_ID);
 	if (!si_tmp)
 		return NULL;
 
 	si = subvol_uuid_search(&s->sus, 0, si_tmp->parent_uuid, 0, NULL,
-			subvol_search_by_uuid);
+			SUBVOL_SEARCH_BY_UUID);
 	free(si_tmp->path);
 	free(si_tmp);
 	return si;
@@ -127,7 +127,7 @@ static int find_good_parent(struct btrfs_send *s, u64 root_id, u64 *found)
 		free(parent2->path);
 		free(parent2);
 		parent2 = subvol_uuid_search(&s->sus, s->clone_sources[i], NULL,
-				0, NULL, subvol_search_by_root_id);
+				0, NULL, SUBVOL_SEARCH_BY_ROOT_ID);
 
 		if (!parent2) {
 			ret = -ENOENT;
props.c +3 -3
index c7c6752..3a4798f 100644
@@ -189,11 +189,11 @@ out:
 
 
 const struct prop_handler prop_handlers[] = {
-	{"ro", "Set/get read-only flag of subvolume.", 0, prop_object_subvol,
+	{"ro", "Set/get read-only flag of subvolume.", 0, PROP_OBJECT_SUBVOL,
 	 prop_read_only},
 	{"label", "Set/get label of device.", 0,
-	 prop_object_dev | prop_object_root, prop_label},
+	 PROP_OBJECT_DEV | PROP_OBJECT_ROOT, prop_label},
 	{"compression", "Set/get compression for a file or directory", 0,
-	 prop_object_inode, prop_compression},
+	 PROP_OBJECT_INODE, prop_compression},
 	{0, 0, 0, 0, 0}
 };
props.h +5 -5
index faa4410..21ba8a2 100644
@@ -18,11 +18,11 @@
 #define PROPS_H_
 
 enum prop_object_type {
-	prop_object_dev		= (1 << 0),
-	prop_object_root	= (1 << 1),
-	prop_object_subvol	= (1 << 2),
-	prop_object_inode	= (1 << 3),
-	__prop_object_max,
+	PROP_OBJECT_DEV		= (1 << 0),
+	PROP_OBJECT_ROOT	= (1 << 1),
+	PROP_OBJECT_SUBVOL	= (1 << 2),
+	PROP_OBJECT_INODE	= (1 << 3),
+	__PROP_OBJECT_MAX,
 };
 
 typedef int (*prop_handler_t)(enum prop_object_type type,
send-utils.c +25 -25

136 lines not on this page · raw message

send-utils.h +4 -4
index f451c1c..2617981 100644
@@ -37,10 +37,10 @@ extern "C" {
 #define BTRFS_COMPAT_SEND_NO_UUID_TREE 1
 
 enum subvol_search_type {
-	subvol_search_by_root_id,
-	subvol_search_by_uuid,
-	subvol_search_by_received_uuid,
-	subvol_search_by_path,
+	SUBVOL_SEARCH_BY_ROOT_ID,
+	SUBVOL_SEARCH_BY_UUID,
+	SUBVOL_SEARCH_BY_RECEIVED_UUID,
+	SUBVOL_SEARCH_BY_PATH,
 };
 
 struct subvol_info {
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Satoru Takeuchi

Sorry, I forgot to add Signed-off-by line.

---
From: Satoru Takeuchi <[email protected]>

"notused" is not necessary. Set 1 to the first entry is enough.

---
 ioctl.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
ioctl.h +1 -2
index 2c2c7c1..c377b96 100644
@@ -474,8 +474,7 @@ struct btrfs_ioctl_qgroup_create_args {
 
 /* Error codes as returned by the kernel */
 enum btrfs_err_code {
-	notused,
-	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
+	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
 	BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
 	BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
 	BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,

-- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 6 lines · Satoru Takeuchi

Sorry, I forgot to add Signed-off-by line.

---
From: Satoru Takeuchi <[email protected]>

"notused" is not necessary. Set 1 to the first entry is enough.

Hi Satoru,

Actually, the struct is copied from the kernel header include/uapi/linux/btrfs.h.
I think they should stay the same, so either change the kernel header in another path, or just keep them in old style.

Thanks,
Gui

Quoted 26 lines
---
 ioctl.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
ioctl.h +1 -4
index 2c2c7c1..c377b96 100644
@@ -474,8 +474,7 @@ struct btrfs_ioctl_qgroup_create_args {
 
 /* Error codes as returned by the kernel */
 enum btrfs_err_code {
-	notused,
-	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
+	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
 	BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
 	BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
 	BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
-- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Hi Gui,

Quoted 6 lines · Gui Hecheng
Quoted 5 lines · Satoru Takeuchi

Sorry, I forgot to add Signed-off-by line.

---
From: Satoru Takeuchi <[email protected]>

Quoted 8 lines
Quoted 1 line

"notused" is not necessary. Set 1 to the first entry is enough.

Hi Satoru,

Actually, the struct is copied from the kernel header include/uapi/linux/btrfs.h.
I think they should stay the same, so either change the kernel header in another path, or just keep them in old style.

OK, I'll send also kernel patches soon.

Thanks,
Satoru

Quoted 32 lines

Thanks,
Gui

Quoted 26 lines
---
  ioctl.h | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
ioctl.h +1 -4
index 2c2c7c1..c377b96 100644
@@ -474,8 +474,7 @@ struct btrfs_ioctl_qgroup_create_args {
 
  /* Error codes as returned by the kernel */
  enum btrfs_err_code {
-	notused,
-	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
+	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
  	BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
  	BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
  	BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
-- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
 
--

To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Re: [PATCH 2/2] Capitalize elements in enum for improve readability.

In reply to Satoru Takeuchi
Quoted 4 lines · Satoru Takeuchi
send-utils.h +0 -0
@@ -37,10 +37,10 @@ extern "C" {
 #define BTRFS_COMPAT_SEND_NO_UUID_TREE 1

send-utils.h extern "C" { · line 43

Quoted 10 lines
send-utils.h +4 -4
 
 enum subvol_search_type {
-	subvol_search_by_root_id,
-	subvol_search_by_uuid,
-	subvol_search_by_received_uuid,
-	subvol_search_by_path,
+	SUBVOL_SEARCH_BY_ROOT_ID,
+	SUBVOL_SEARCH_BY_UUID,
+	SUBVOL_SEARCH_BY_RECEIVED_UUID,
+	SUBVOL_SEARCH_BY_PATH,

send-utils.h is part of public API, so this would have to be changed in a backward compatible way, but the current library API is underdesigned so I don't think this patch will help.

Getting the library right is on the todo list but it will take some time and some reorganization of sources will have to take place before that.