* [BTRFS-PROGS][PATCH][CLEANUP] Remove some gotos
@ 2014-12-21 18:07 Goffredo Baroncelli
2014-12-21 18:07 ` [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos Goffredo Baroncelli
2014-12-22 2:29 ` [BTRFS-PROGS][PATCH][CLEANUP] Remove some gotos Wang Shilong
0 siblings, 2 replies; 7+ messages in thread
From: Goffredo Baroncelli @ 2014-12-21 18:07 UTC (permalink / raw)
To: linux-btrfs
Hi all,
before sending this patch I thought twice if it is really worth.
I know the coding style is really a hot topic. But the world
is already too ugly, to allow even that. And it is Merry Christmas,
so let me to make me a gift: a small clean up.
The culprit are some goto found in 'cmds-filesystem.c' inside the
function 'cmd_show()'. These are used instead of an 'if' statement.
I wish you all a Happy Christmas and a successful start to 2015.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos
2014-12-21 18:07 [BTRFS-PROGS][PATCH][CLEANUP] Remove some gotos Goffredo Baroncelli
@ 2014-12-21 18:07 ` Goffredo Baroncelli
2014-12-22 11:34 ` Satoru Takeuchi
2014-12-22 17:32 ` David Sterba
2014-12-22 2:29 ` [BTRFS-PROGS][PATCH][CLEANUP] Remove some gotos Wang Shilong
1 sibling, 2 replies; 7+ messages in thread
From: Goffredo Baroncelli @ 2014-12-21 18:07 UTC (permalink / raw)
To: linux-btrfs; +Cc: Goffredo Baroncelli
Change a spagetti-style code (there are some "interlaced" gotos) to
a more modern style...
This patch removes also some #define from utils.h, which define
constants used only in cmds-filesystems.c . Instead an enum
is used locally in cmds-filesystems.c .
---
cmds-filesystem.c | 106 ++++++++++++++++++++++++++++--------------------------
utils.h | 3 --
2 files changed, 55 insertions(+), 54 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 7eaccb9..08ddb5d 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -40,6 +40,11 @@
#include "list_sort.h"
#include "disk-io.h"
+enum filesystem_show_scan_method {
+ BTRFS_SCAN_ANY,
+ BTRFS_SCAN_MOUNTED,
+ BTRFS_SCAN_LBLKID
+};
/*
* for btrfs fi show, we maintain a hash of fsids we've already printed.
@@ -853,7 +858,7 @@ static int cmd_show(int argc, char **argv)
char *search = NULL;
int ret;
/* default, search both kernel and udev */
- int where = -1;
+ int where = BTRFS_SCAN_ANY;
int type = 0;
char mp[BTRFS_PATH_NAME_MAX + 1];
char path[PATH_MAX];
@@ -930,61 +935,60 @@ static int cmd_show(int argc, char **argv)
uuid_unparse(fsid, uuid_buf);
search = uuid_buf;
type = BTRFS_ARG_UUID;
- goto devs_only;
+ where = BTRFS_SCAN_LBLKID;
}
}
}
- if (where == BTRFS_SCAN_LBLKID)
- goto devs_only;
-
- /* show mounted btrfs */
- ret = btrfs_scan_kernel(search);
- if (search && !ret) {
- /* since search is found we are done */
- goto out;
- }
-
- /* shows mounted only */
- if (where == BTRFS_SCAN_MOUNTED)
- goto out;
-
-devs_only:
- ret = btrfs_scan_lblkid();
-
- if (ret) {
- fprintf(stderr, "ERROR: %d while scanning\n", ret);
- return 1;
- }
-
- found = search_umounted_fs_uuids(&all_uuids, search);
- if (found < 0) {
- fprintf(stderr,
- "ERROR: %d while searching target device\n", ret);
- return 1;
- }
-
- /*
- * The seed/sprout mapping are not detected yet,
- * do mapping build for all umounted fs
- */
- ret = map_seed_devices(&all_uuids);
- if (ret) {
- fprintf(stderr,
- "ERROR: %d while mapping seed devices\n", ret);
- return 1;
+ if (where == BTRFS_SCAN_MOUNTED || where == BTRFS_SCAN_ANY) {
+
+ /* show mounted btrfs */
+ ret = btrfs_scan_kernel(search);
+ if (search && !ret) {
+ /* since search is found we are done */
+ goto out;
+ }
+
}
-
- list_for_each_entry(fs_devices, &all_uuids, list)
- print_one_uuid(fs_devices);
-
- if (search && !found)
- ret = 1;
-
- while (!list_empty(&all_uuids)) {
- fs_devices = list_entry(all_uuids.next,
- struct btrfs_fs_devices, list);
- free_fs_devices(fs_devices);
+
+ if (where == BTRFS_SCAN_LBLKID || where == BTRFS_SCAN_ANY) {
+
+ ret = btrfs_scan_lblkid();
+
+ if (ret) {
+ fprintf(stderr, "ERROR: %d while scanning\n", ret);
+ return 1;
+ }
+
+ found = search_umounted_fs_uuids(&all_uuids, search);
+ if (found < 0) {
+ fprintf(stderr,
+ "ERROR: %d while searching target device\n", ret);
+ return 1;
+ }
+
+ /*
+ * The seed/sprout mapping are not detected yet,
+ * do mapping build for all umounted fs
+ */
+ ret = map_seed_devices(&all_uuids);
+ if (ret) {
+ fprintf(stderr,
+ "ERROR: %d while mapping seed devices\n", ret);
+ return 1;
+ }
+
+ list_for_each_entry(fs_devices, &all_uuids, list)
+ print_one_uuid(fs_devices);
+
+ if (search && !found)
+ ret = 1;
+
+ while (!list_empty(&all_uuids)) {
+ fs_devices = list_entry(all_uuids.next,
+ struct btrfs_fs_devices, list);
+ free_fs_devices(fs_devices);
+ }
}
out:
printf("%s\n", BTRFS_BUILD_VERSION);
diff --git a/utils.h b/utils.h
index 0464c2d..603cdfb 100644
--- a/utils.h
+++ b/utils.h
@@ -26,9 +26,6 @@
#define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
#define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024)
-#define BTRFS_SCAN_MOUNTED (1ULL << 0)
-#define BTRFS_SCAN_LBLKID (1ULL << 1)
-
#define BTRFS_UPDATE_KERNEL 1
#define BTRFS_ARG_UNKNOWN 0
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [BTRFS-PROGS][PATCH][CLEANUP] Remove some gotos
2014-12-21 18:07 [BTRFS-PROGS][PATCH][CLEANUP] Remove some gotos Goffredo Baroncelli
2014-12-21 18:07 ` [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos Goffredo Baroncelli
@ 2014-12-22 2:29 ` Wang Shilong
1 sibling, 0 replies; 7+ messages in thread
From: Wang Shilong @ 2014-12-22 2:29 UTC (permalink / raw)
To: Goffredo Baroncelli; +Cc: linux-btrfs
Hello,
>
> Hi all,
>
> before sending this patch I thought twice if it is really worth.
> I know the coding style is really a hot topic. But the world
> is already too ugly, to allow even that. And it is Merry Christmas,
> so let me to make me a gift: a small clean up.
>
> The culprit are some goto found in 'cmds-filesystem.c' inside the
> function 'cmd_show()'. These are used instead of an 'if' statement.
>
> I wish you all a Happy Christmas and a successful start to 2015.
I think Nice cleanups are always good for Btrfs..Just take a look
at Btrfs kernel codes etc which really scared a lot of code reviewers and newbies..
Merry Chirismas guys. ^_^
>
>
>
> --
> 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
Best Regards,
Wang Shilong
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos
2014-12-21 18:07 ` [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos Goffredo Baroncelli
@ 2014-12-22 11:34 ` Satoru Takeuchi
2014-12-22 19:07 ` Goffredo Baroncelli
2014-12-22 17:32 ` David Sterba
1 sibling, 1 reply; 7+ messages in thread
From: Satoru Takeuchi @ 2014-12-22 11:34 UTC (permalink / raw)
To: Goffredo Baroncelli, linux-btrfs@vger.kernel.org
On 2014/12/22 3:07, Goffredo Baroncelli wrote:
> Change a spagetti-style code (there are some "interlaced" gotos) to
> a more modern style...
>
> This patch removes also some #define from utils.h, which define
> constants used only in cmds-filesystems.c . Instead an enum
> is used locally in cmds-filesystems.c .
I'm happy if you have a regression test for this patch
since such kind of change often cause regression.
Thanks,
Satoru
> ---
> cmds-filesystem.c | 106 ++++++++++++++++++++++++++++--------------------------
> utils.h | 3 --
> 2 files changed, 55 insertions(+), 54 deletions(-)
>
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index 7eaccb9..08ddb5d 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -40,6 +40,11 @@
> #include "list_sort.h"
> #include "disk-io.h"
>
> +enum filesystem_show_scan_method {
> + BTRFS_SCAN_ANY,
> + BTRFS_SCAN_MOUNTED,
> + BTRFS_SCAN_LBLKID
> +};
>
> /*
> * for btrfs fi show, we maintain a hash of fsids we've already printed.
> @@ -853,7 +858,7 @@ static int cmd_show(int argc, char **argv)
> char *search = NULL;
> int ret;
> /* default, search both kernel and udev */
> - int where = -1;
> + int where = BTRFS_SCAN_ANY;
> int type = 0;
> char mp[BTRFS_PATH_NAME_MAX + 1];
> char path[PATH_MAX];
> @@ -930,61 +935,60 @@ static int cmd_show(int argc, char **argv)
> uuid_unparse(fsid, uuid_buf);
> search = uuid_buf;
> type = BTRFS_ARG_UUID;
> - goto devs_only;
> + where = BTRFS_SCAN_LBLKID;
> }
> }
> }
>
> - if (where == BTRFS_SCAN_LBLKID)
> - goto devs_only;
> -
> - /* show mounted btrfs */
> - ret = btrfs_scan_kernel(search);
> - if (search && !ret) {
> - /* since search is found we are done */
> - goto out;
> - }
> -
> - /* shows mounted only */
> - if (where == BTRFS_SCAN_MOUNTED)
> - goto out;
> -
> -devs_only:
> - ret = btrfs_scan_lblkid();
> -
> - if (ret) {
> - fprintf(stderr, "ERROR: %d while scanning\n", ret);
> - return 1;
> - }
> -
> - found = search_umounted_fs_uuids(&all_uuids, search);
> - if (found < 0) {
> - fprintf(stderr,
> - "ERROR: %d while searching target device\n", ret);
> - return 1;
> - }
> -
> - /*
> - * The seed/sprout mapping are not detected yet,
> - * do mapping build for all umounted fs
> - */
> - ret = map_seed_devices(&all_uuids);
> - if (ret) {
> - fprintf(stderr,
> - "ERROR: %d while mapping seed devices\n", ret);
> - return 1;
> + if (where == BTRFS_SCAN_MOUNTED || where == BTRFS_SCAN_ANY) {
> +
> + /* show mounted btrfs */
> + ret = btrfs_scan_kernel(search);
> + if (search && !ret) {
> + /* since search is found we are done */
> + goto out;
> + }
> +
> }
> -
> - list_for_each_entry(fs_devices, &all_uuids, list)
> - print_one_uuid(fs_devices);
> -
> - if (search && !found)
> - ret = 1;
> -
> - while (!list_empty(&all_uuids)) {
> - fs_devices = list_entry(all_uuids.next,
> - struct btrfs_fs_devices, list);
> - free_fs_devices(fs_devices);
> +
> + if (where == BTRFS_SCAN_LBLKID || where == BTRFS_SCAN_ANY) {
> +
> + ret = btrfs_scan_lblkid();
> +
> + if (ret) {
> + fprintf(stderr, "ERROR: %d while scanning\n", ret);
> + return 1;
> + }
> +
> + found = search_umounted_fs_uuids(&all_uuids, search);
> + if (found < 0) {
> + fprintf(stderr,
> + "ERROR: %d while searching target device\n", ret);
> + return 1;
> + }
> +
> + /*
> + * The seed/sprout mapping are not detected yet,
> + * do mapping build for all umounted fs
> + */
> + ret = map_seed_devices(&all_uuids);
> + if (ret) {
> + fprintf(stderr,
> + "ERROR: %d while mapping seed devices\n", ret);
> + return 1;
> + }
> +
> + list_for_each_entry(fs_devices, &all_uuids, list)
> + print_one_uuid(fs_devices);
> +
> + if (search && !found)
> + ret = 1;
> +
> + while (!list_empty(&all_uuids)) {
> + fs_devices = list_entry(all_uuids.next,
> + struct btrfs_fs_devices, list);
> + free_fs_devices(fs_devices);
> + }
> }
> out:
> printf("%s\n", BTRFS_BUILD_VERSION);
> diff --git a/utils.h b/utils.h
> index 0464c2d..603cdfb 100644
> --- a/utils.h
> +++ b/utils.h
> @@ -26,9 +26,6 @@
> #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
> #define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024)
>
> -#define BTRFS_SCAN_MOUNTED (1ULL << 0)
> -#define BTRFS_SCAN_LBLKID (1ULL << 1)
> -
> #define BTRFS_UPDATE_KERNEL 1
>
> #define BTRFS_ARG_UNKNOWN 0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos
2014-12-21 18:07 ` [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos Goffredo Baroncelli
2014-12-22 11:34 ` Satoru Takeuchi
@ 2014-12-22 17:32 ` David Sterba
1 sibling, 0 replies; 7+ messages in thread
From: David Sterba @ 2014-12-22 17:32 UTC (permalink / raw)
To: Goffredo Baroncelli; +Cc: linux-btrfs, Goffredo Baroncelli
... Subject: [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos
You're being too creative with the subjects and lack the preferred
formatting. If you're going to submit more patches, please get it right
so I don't have to fix it repeatedly manually. There's a wiki page
https://btrfs.wiki.kernel.org/index.php/Developer's_FAQ
that should cover the topic.
On Sun, Dec 21, 2014 at 07:07:18PM +0100, Goffredo Baroncelli wrote:
> Change a spagetti-style code (there are some "interlaced" gotos) to
> a more modern style...
>
> This patch removes also some #define from utils.h, which define
> constants used only in cmds-filesystems.c . Instead an enum
> is used locally in cmds-filesystems.c .
That's an unrelated change, please put it into a separate patch.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos
2014-12-22 11:34 ` Satoru Takeuchi
@ 2014-12-22 19:07 ` Goffredo Baroncelli
2014-12-24 3:04 ` Satoru Takeuchi
0 siblings, 1 reply; 7+ messages in thread
From: Goffredo Baroncelli @ 2014-12-22 19:07 UTC (permalink / raw)
To: Satoru Takeuchi, linux-btrfs@vger.kernel.org
On 12/22/2014 12:34 PM, Satoru Takeuchi wrote:
> On 2014/12/22 3:07, Goffredo Baroncelli wrote:
>> Change a spagetti-style code (there are some "interlaced" gotos) to
>> a more modern style...
>>
>> This patch removes also some #define from utils.h, which define
>> constants used only in cmds-filesystems.c . Instead an enum
>> is used locally in cmds-filesystems.c .
>
> I'm happy if you have a regression test for this patch
> since such kind of change often cause regression.
I am impressed, this is the first time that I received this kind
of request on btrfs ml....
In which form you want this "regression test" ? I see a
directory tests/ under btrfs-progs; but also I saw
reference to xfstest...
>
> Thanks,
> Satoru
>
>> ---
>> cmds-filesystem.c | 106 ++++++++++++++++++++++++++++--------------------------
>> utils.h | 3 --
>> 2 files changed, 55 insertions(+), 54 deletions(-)
>>
>> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
>> index 7eaccb9..08ddb5d 100644
>> --- a/cmds-filesystem.c
>> +++ b/cmds-filesystem.c
>> @@ -40,6 +40,11 @@
>> #include "list_sort.h"
>> #include "disk-io.h"
>>
>> +enum filesystem_show_scan_method {
>> + BTRFS_SCAN_ANY,
>> + BTRFS_SCAN_MOUNTED,
>> + BTRFS_SCAN_LBLKID
>> +};
>>
>> /*
>> * for btrfs fi show, we maintain a hash of fsids we've already printed.
>> @@ -853,7 +858,7 @@ static int cmd_show(int argc, char **argv)
>> char *search = NULL;
>> int ret;
>> /* default, search both kernel and udev */
>> - int where = -1;
>> + int where = BTRFS_SCAN_ANY;
>> int type = 0;
>> char mp[BTRFS_PATH_NAME_MAX + 1];
>> char path[PATH_MAX];
>> @@ -930,61 +935,60 @@ static int cmd_show(int argc, char **argv)
>> uuid_unparse(fsid, uuid_buf);
>> search = uuid_buf;
>> type = BTRFS_ARG_UUID;
>> - goto devs_only;
>> + where = BTRFS_SCAN_LBLKID;
>> }
>> }
>> }
>>
>> - if (where == BTRFS_SCAN_LBLKID)
>> - goto devs_only;
>> -
>> - /* show mounted btrfs */
>> - ret = btrfs_scan_kernel(search);
>> - if (search && !ret) {
>> - /* since search is found we are done */
>> - goto out;
>> - }
>> -
>> - /* shows mounted only */
>> - if (where == BTRFS_SCAN_MOUNTED)
>> - goto out;
>> -
>> -devs_only:
>> - ret = btrfs_scan_lblkid();
>> -
>> - if (ret) {
>> - fprintf(stderr, "ERROR: %d while scanning\n", ret);
>> - return 1;
>> - }
>> -
>> - found = search_umounted_fs_uuids(&all_uuids, search);
>> - if (found < 0) {
>> - fprintf(stderr,
>> - "ERROR: %d while searching target device\n", ret);
>> - return 1;
>> - }
>> -
>> - /*
>> - * The seed/sprout mapping are not detected yet,
>> - * do mapping build for all umounted fs
>> - */
>> - ret = map_seed_devices(&all_uuids);
>> - if (ret) {
>> - fprintf(stderr,
>> - "ERROR: %d while mapping seed devices\n", ret);
>> - return 1;
>> + if (where == BTRFS_SCAN_MOUNTED || where == BTRFS_SCAN_ANY) {
>> +
>> + /* show mounted btrfs */
>> + ret = btrfs_scan_kernel(search);
>> + if (search && !ret) {
>> + /* since search is found we are done */
>> + goto out;
>> + }
>> +
>> }
>> -
>> - list_for_each_entry(fs_devices, &all_uuids, list)
>> - print_one_uuid(fs_devices);
>> -
>> - if (search && !found)
>> - ret = 1;
>> -
>> - while (!list_empty(&all_uuids)) {
>> - fs_devices = list_entry(all_uuids.next,
>> - struct btrfs_fs_devices, list);
>> - free_fs_devices(fs_devices);
>> +
>> + if (where == BTRFS_SCAN_LBLKID || where == BTRFS_SCAN_ANY) {
>> +
>> + ret = btrfs_scan_lblkid();
>> +
>> + if (ret) {
>> + fprintf(stderr, "ERROR: %d while scanning\n", ret);
>> + return 1;
>> + }
>> +
>> + found = search_umounted_fs_uuids(&all_uuids, search);
>> + if (found < 0) {
>> + fprintf(stderr,
>> + "ERROR: %d while searching target device\n", ret);
>> + return 1;
>> + }
>> +
>> + /*
>> + * The seed/sprout mapping are not detected yet,
>> + * do mapping build for all umounted fs
>> + */
>> + ret = map_seed_devices(&all_uuids);
>> + if (ret) {
>> + fprintf(stderr,
>> + "ERROR: %d while mapping seed devices\n", ret);
>> + return 1;
>> + }
>> +
>> + list_for_each_entry(fs_devices, &all_uuids, list)
>> + print_one_uuid(fs_devices);
>> +
>> + if (search && !found)
>> + ret = 1;
>> +
>> + while (!list_empty(&all_uuids)) {
>> + fs_devices = list_entry(all_uuids.next,
>> + struct btrfs_fs_devices, list);
>> + free_fs_devices(fs_devices);
>> + }
>> }
>> out:
>> printf("%s\n", BTRFS_BUILD_VERSION);
>> diff --git a/utils.h b/utils.h
>> index 0464c2d..603cdfb 100644
>> --- a/utils.h
>> +++ b/utils.h
>> @@ -26,9 +26,6 @@
>> #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
>> #define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024)
>>
>> -#define BTRFS_SCAN_MOUNTED (1ULL << 0)
>> -#define BTRFS_SCAN_LBLKID (1ULL << 1)
>> -
>> #define BTRFS_UPDATE_KERNEL 1
>>
>> #define BTRFS_ARG_UNKNOWN 0
>>
>
>
--
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos
2014-12-22 19:07 ` Goffredo Baroncelli
@ 2014-12-24 3:04 ` Satoru Takeuchi
0 siblings, 0 replies; 7+ messages in thread
From: Satoru Takeuchi @ 2014-12-24 3:04 UTC (permalink / raw)
To: kreijack, linux-btrfs@vger.kernel.org
Hi Goffredo,
On 2014/12/23 4:07, Goffredo Baroncelli wrote:
> On 12/22/2014 12:34 PM, Satoru Takeuchi wrote:
>> On 2014/12/22 3:07, Goffredo Baroncelli wrote:
>>> Change a spagetti-style code (there are some "interlaced" gotos) to
>>> a more modern style...
>>>
>>> This patch removes also some #define from utils.h, which define
>>> constants used only in cmds-filesystems.c . Instead an enum
>>> is used locally in cmds-filesystems.c .
>>
>> I'm happy if you have a regression test for this patch
>> since such kind of change often cause regression.
>
> I am impressed, this is the first time that I received this kind
> of request on btrfs ml....
It's because I'd like to contribute to Btrfs not only
by submitting patches, but also by reviewing/testing
other guy's patches to improve its quality better.
>
> In which form you want this "regression test" ? I see a
> directory tests/ under btrfs-progs; but also I saw
> reference to xfstest...
Any format is OK, for example a simple shell script.
Thanks,
Satoru
>
>
>
>>
>> Thanks,
>> Satoru
>>
>>> ---
>>> cmds-filesystem.c | 106 ++++++++++++++++++++++++++++--------------------------
>>> utils.h | 3 --
>>> 2 files changed, 55 insertions(+), 54 deletions(-)
>>>
>>> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
>>> index 7eaccb9..08ddb5d 100644
>>> --- a/cmds-filesystem.c
>>> +++ b/cmds-filesystem.c
>>> @@ -40,6 +40,11 @@
>>> #include "list_sort.h"
>>> #include "disk-io.h"
>>>
>>> +enum filesystem_show_scan_method {
>>> + BTRFS_SCAN_ANY,
>>> + BTRFS_SCAN_MOUNTED,
>>> + BTRFS_SCAN_LBLKID
>>> +};
>>>
>>> /*
>>> * for btrfs fi show, we maintain a hash of fsids we've already printed.
>>> @@ -853,7 +858,7 @@ static int cmd_show(int argc, char **argv)
>>> char *search = NULL;
>>> int ret;
>>> /* default, search both kernel and udev */
>>> - int where = -1;
>>> + int where = BTRFS_SCAN_ANY;
>>> int type = 0;
>>> char mp[BTRFS_PATH_NAME_MAX + 1];
>>> char path[PATH_MAX];
>>> @@ -930,61 +935,60 @@ static int cmd_show(int argc, char **argv)
>>> uuid_unparse(fsid, uuid_buf);
>>> search = uuid_buf;
>>> type = BTRFS_ARG_UUID;
>>> - goto devs_only;
>>> + where = BTRFS_SCAN_LBLKID;
>>> }
>>> }
>>> }
>>>
>>> - if (where == BTRFS_SCAN_LBLKID)
>>> - goto devs_only;
>>> -
>>> - /* show mounted btrfs */
>>> - ret = btrfs_scan_kernel(search);
>>> - if (search && !ret) {
>>> - /* since search is found we are done */
>>> - goto out;
>>> - }
>>> -
>>> - /* shows mounted only */
>>> - if (where == BTRFS_SCAN_MOUNTED)
>>> - goto out;
>>> -
>>> -devs_only:
>>> - ret = btrfs_scan_lblkid();
>>> -
>>> - if (ret) {
>>> - fprintf(stderr, "ERROR: %d while scanning\n", ret);
>>> - return 1;
>>> - }
>>> -
>>> - found = search_umounted_fs_uuids(&all_uuids, search);
>>> - if (found < 0) {
>>> - fprintf(stderr,
>>> - "ERROR: %d while searching target device\n", ret);
>>> - return 1;
>>> - }
>>> -
>>> - /*
>>> - * The seed/sprout mapping are not detected yet,
>>> - * do mapping build for all umounted fs
>>> - */
>>> - ret = map_seed_devices(&all_uuids);
>>> - if (ret) {
>>> - fprintf(stderr,
>>> - "ERROR: %d while mapping seed devices\n", ret);
>>> - return 1;
>>> + if (where == BTRFS_SCAN_MOUNTED || where == BTRFS_SCAN_ANY) {
>>> +
>>> + /* show mounted btrfs */
>>> + ret = btrfs_scan_kernel(search);
>>> + if (search && !ret) {
>>> + /* since search is found we are done */
>>> + goto out;
>>> + }
>>> +
>>> }
>>> -
>>> - list_for_each_entry(fs_devices, &all_uuids, list)
>>> - print_one_uuid(fs_devices);
>>> -
>>> - if (search && !found)
>>> - ret = 1;
>>> -
>>> - while (!list_empty(&all_uuids)) {
>>> - fs_devices = list_entry(all_uuids.next,
>>> - struct btrfs_fs_devices, list);
>>> - free_fs_devices(fs_devices);
>>> +
>>> + if (where == BTRFS_SCAN_LBLKID || where == BTRFS_SCAN_ANY) {
>>> +
>>> + ret = btrfs_scan_lblkid();
>>> +
>>> + if (ret) {
>>> + fprintf(stderr, "ERROR: %d while scanning\n", ret);
>>> + return 1;
>>> + }
>>> +
>>> + found = search_umounted_fs_uuids(&all_uuids, search);
>>> + if (found < 0) {
>>> + fprintf(stderr,
>>> + "ERROR: %d while searching target device\n", ret);
>>> + return 1;
>>> + }
>>> +
>>> + /*
>>> + * The seed/sprout mapping are not detected yet,
>>> + * do mapping build for all umounted fs
>>> + */
>>> + ret = map_seed_devices(&all_uuids);
>>> + if (ret) {
>>> + fprintf(stderr,
>>> + "ERROR: %d while mapping seed devices\n", ret);
>>> + return 1;
>>> + }
>>> +
>>> + list_for_each_entry(fs_devices, &all_uuids, list)
>>> + print_one_uuid(fs_devices);
>>> +
>>> + if (search && !found)
>>> + ret = 1;
>>> +
>>> + while (!list_empty(&all_uuids)) {
>>> + fs_devices = list_entry(all_uuids.next,
>>> + struct btrfs_fs_devices, list);
>>> + free_fs_devices(fs_devices);
>>> + }
>>> }
>>> out:
>>> printf("%s\n", BTRFS_BUILD_VERSION);
>>> diff --git a/utils.h b/utils.h
>>> index 0464c2d..603cdfb 100644
>>> --- a/utils.h
>>> +++ b/utils.h
>>> @@ -26,9 +26,6 @@
>>> #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
>>> #define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024)
>>>
>>> -#define BTRFS_SCAN_MOUNTED (1ULL << 0)
>>> -#define BTRFS_SCAN_LBLKID (1ULL << 1)
>>> -
>>> #define BTRFS_UPDATE_KERNEL 1
>>>
>>> #define BTRFS_ARG_UNKNOWN 0
>>>
>>
>>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-12-24 3:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-21 18:07 [BTRFS-PROGS][PATCH][CLEANUP] Remove some gotos Goffredo Baroncelli
2014-12-21 18:07 ` [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos Goffredo Baroncelli
2014-12-22 11:34 ` Satoru Takeuchi
2014-12-22 19:07 ` Goffredo Baroncelli
2014-12-24 3:04 ` Satoru Takeuchi
2014-12-22 17:32 ` David Sterba
2014-12-22 2:29 ` [BTRFS-PROGS][PATCH][CLEANUP] Remove some gotos Wang Shilong
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).