diff options
author | Sami Tolvanen <samitolvanen@google.com> | 2015-11-04 21:02:32 -0500 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2015-12-10 10:39:00 -0500 |
commit | 753c1fd02807cb43a1c5d01d75d454054d46bdad (patch) | |
tree | 94c6f1af05093bdd59657985ab45738516a1586d | |
parent | 6dbeda3469ced777bc3138ed5918f7ae79670b7b (diff) |
dm verity: separate function for parsing opt args
Move optional argument parsing into a separate function to make it
easier to add more of them without making verity_ctr even longer.
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
-rw-r--r-- | drivers/md/dm-verity.c | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/drivers/md/dm-verity.c b/drivers/md/dm-verity.c index 24517055bd8e..b0a53c3b926d 100644 --- a/drivers/md/dm-verity.c +++ b/drivers/md/dm-verity.c | |||
@@ -34,6 +34,8 @@ | |||
34 | #define DM_VERITY_OPT_LOGGING "ignore_corruption" | 34 | #define DM_VERITY_OPT_LOGGING "ignore_corruption" |
35 | #define DM_VERITY_OPT_RESTART "restart_on_corruption" | 35 | #define DM_VERITY_OPT_RESTART "restart_on_corruption" |
36 | 36 | ||
37 | #define DM_VERITY_OPTS_MAX 1 | ||
38 | |||
37 | static unsigned dm_verity_prefetch_cluster = DM_VERITY_DEFAULT_PREFETCH_SIZE; | 39 | static unsigned dm_verity_prefetch_cluster = DM_VERITY_DEFAULT_PREFETCH_SIZE; |
38 | 40 | ||
39 | module_param_named(prefetch_cluster, dm_verity_prefetch_cluster, uint, S_IRUGO | S_IWUSR); | 41 | module_param_named(prefetch_cluster, dm_verity_prefetch_cluster, uint, S_IRUGO | S_IWUSR); |
@@ -721,6 +723,44 @@ static void verity_dtr(struct dm_target *ti) | |||
721 | kfree(v); | 723 | kfree(v); |
722 | } | 724 | } |
723 | 725 | ||
726 | static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v) | ||
727 | { | ||
728 | int r; | ||
729 | unsigned argc; | ||
730 | struct dm_target *ti = v->ti; | ||
731 | const char *arg_name; | ||
732 | |||
733 | static struct dm_arg _args[] = { | ||
734 | {0, DM_VERITY_OPTS_MAX, "Invalid number of feature args"}, | ||
735 | }; | ||
736 | |||
737 | r = dm_read_arg_group(_args, as, &argc, &ti->error); | ||
738 | if (r) | ||
739 | return -EINVAL; | ||
740 | |||
741 | if (!argc) | ||
742 | return 0; | ||
743 | |||
744 | do { | ||
745 | arg_name = dm_shift_arg(as); | ||
746 | argc--; | ||
747 | |||
748 | if (!strcasecmp(arg_name, DM_VERITY_OPT_LOGGING)) { | ||
749 | v->mode = DM_VERITY_MODE_LOGGING; | ||
750 | continue; | ||
751 | |||
752 | } else if (!strcasecmp(arg_name, DM_VERITY_OPT_RESTART)) { | ||
753 | v->mode = DM_VERITY_MODE_RESTART; | ||
754 | continue; | ||
755 | } | ||
756 | |||
757 | ti->error = "Unrecognized verity feature request"; | ||
758 | return -EINVAL; | ||
759 | } while (argc && !r); | ||
760 | |||
761 | return r; | ||
762 | } | ||
763 | |||
724 | /* | 764 | /* |
725 | * Target parameters: | 765 | * Target parameters: |
726 | * <version> The current format is version 1. | 766 | * <version> The current format is version 1. |
@@ -739,18 +779,13 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) | |||
739 | { | 779 | { |
740 | struct dm_verity *v; | 780 | struct dm_verity *v; |
741 | struct dm_arg_set as; | 781 | struct dm_arg_set as; |
742 | const char *opt_string; | 782 | unsigned int num; |
743 | unsigned int num, opt_params; | ||
744 | unsigned long long num_ll; | 783 | unsigned long long num_ll; |
745 | int r; | 784 | int r; |
746 | int i; | 785 | int i; |
747 | sector_t hash_position; | 786 | sector_t hash_position; |
748 | char dummy; | 787 | char dummy; |
749 | 788 | ||
750 | static struct dm_arg _args[] = { | ||
751 | {0, 1, "Invalid number of feature args"}, | ||
752 | }; | ||
753 | |||
754 | v = kzalloc(sizeof(struct dm_verity), GFP_KERNEL); | 789 | v = kzalloc(sizeof(struct dm_verity), GFP_KERNEL); |
755 | if (!v) { | 790 | if (!v) { |
756 | ti->error = "Cannot allocate verity structure"; | 791 | ti->error = "Cannot allocate verity structure"; |
@@ -895,29 +930,9 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) | |||
895 | as.argc = argc; | 930 | as.argc = argc; |
896 | as.argv = argv; | 931 | as.argv = argv; |
897 | 932 | ||
898 | r = dm_read_arg_group(_args, &as, &opt_params, &ti->error); | 933 | r = verity_parse_opt_args(&as, v); |
899 | if (r) | 934 | if (r < 0) |
900 | goto bad; | 935 | goto bad; |
901 | |||
902 | while (opt_params) { | ||
903 | opt_params--; | ||
904 | opt_string = dm_shift_arg(&as); | ||
905 | if (!opt_string) { | ||
906 | ti->error = "Not enough feature arguments"; | ||
907 | r = -EINVAL; | ||
908 | goto bad; | ||
909 | } | ||
910 | |||
911 | if (!strcasecmp(opt_string, DM_VERITY_OPT_LOGGING)) | ||
912 | v->mode = DM_VERITY_MODE_LOGGING; | ||
913 | else if (!strcasecmp(opt_string, DM_VERITY_OPT_RESTART)) | ||
914 | v->mode = DM_VERITY_MODE_RESTART; | ||
915 | else { | ||
916 | ti->error = "Invalid feature arguments"; | ||
917 | r = -EINVAL; | ||
918 | goto bad; | ||
919 | } | ||
920 | } | ||
921 | } | 936 | } |
922 | 937 | ||
923 | v->hash_per_block_bits = | 938 | v->hash_per_block_bits = |