diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2013-10-14 09:48:04 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2013-12-16 13:57:50 -0500 |
commit | 8206937916bce22e79531f1eb2c54947ea3276a1 (patch) | |
tree | 0c67daf8d7c86393f405b6e7197631eb0a30c199 /drivers/scsi/scsi_debug.c | |
parent | 319e2e3f63c348a9b66db4667efa73178e18b17d (diff) |
[SCSI] scsi_debug: simplify creation and destruction of driver attribute files
Instead of repeatedly calling driver_create_file() to create driver
attribute files, This achieves the same thing by constructing an array
of driver_attribute and setting it to bus_type->drv_groups.
This change simplifies both creation and destruction of the attribute
files, and also removes sparse warning caused by driver_attributes which
are unnecessarily declared as global.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi/scsi_debug.c')
-rw-r--r-- | drivers/scsi/scsi_debug.c | 266 |
1 files changed, 106 insertions, 160 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 80b8b10edf41..2decc6417518 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c | |||
@@ -2873,13 +2873,13 @@ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host) | |||
2873 | return 0; | 2873 | return 0; |
2874 | } | 2874 | } |
2875 | 2875 | ||
2876 | static ssize_t sdebug_delay_show(struct device_driver * ddp, char * buf) | 2876 | static ssize_t delay_show(struct device_driver *ddp, char *buf) |
2877 | { | 2877 | { |
2878 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_delay); | 2878 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_delay); |
2879 | } | 2879 | } |
2880 | 2880 | ||
2881 | static ssize_t sdebug_delay_store(struct device_driver * ddp, | 2881 | static ssize_t delay_store(struct device_driver *ddp, const char *buf, |
2882 | const char * buf, size_t count) | 2882 | size_t count) |
2883 | { | 2883 | { |
2884 | int delay; | 2884 | int delay; |
2885 | char work[20]; | 2885 | char work[20]; |
@@ -2892,16 +2892,15 @@ static ssize_t sdebug_delay_store(struct device_driver * ddp, | |||
2892 | } | 2892 | } |
2893 | return -EINVAL; | 2893 | return -EINVAL; |
2894 | } | 2894 | } |
2895 | DRIVER_ATTR(delay, S_IRUGO | S_IWUSR, sdebug_delay_show, | 2895 | static DRIVER_ATTR_RW(delay); |
2896 | sdebug_delay_store); | ||
2897 | 2896 | ||
2898 | static ssize_t sdebug_opts_show(struct device_driver * ddp, char * buf) | 2897 | static ssize_t opts_show(struct device_driver *ddp, char *buf) |
2899 | { | 2898 | { |
2900 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", scsi_debug_opts); | 2899 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", scsi_debug_opts); |
2901 | } | 2900 | } |
2902 | 2901 | ||
2903 | static ssize_t sdebug_opts_store(struct device_driver * ddp, | 2902 | static ssize_t opts_store(struct device_driver *ddp, const char *buf, |
2904 | const char * buf, size_t count) | 2903 | size_t count) |
2905 | { | 2904 | { |
2906 | int opts; | 2905 | int opts; |
2907 | char work[20]; | 2906 | char work[20]; |
@@ -2921,15 +2920,14 @@ opts_done: | |||
2921 | scsi_debug_cmnd_count = 0; | 2920 | scsi_debug_cmnd_count = 0; |
2922 | return count; | 2921 | return count; |
2923 | } | 2922 | } |
2924 | DRIVER_ATTR(opts, S_IRUGO | S_IWUSR, sdebug_opts_show, | 2923 | static DRIVER_ATTR_RW(opts); |
2925 | sdebug_opts_store); | ||
2926 | 2924 | ||
2927 | static ssize_t sdebug_ptype_show(struct device_driver * ddp, char * buf) | 2925 | static ssize_t ptype_show(struct device_driver *ddp, char *buf) |
2928 | { | 2926 | { |
2929 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_ptype); | 2927 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_ptype); |
2930 | } | 2928 | } |
2931 | static ssize_t sdebug_ptype_store(struct device_driver * ddp, | 2929 | static ssize_t ptype_store(struct device_driver *ddp, const char *buf, |
2932 | const char * buf, size_t count) | 2930 | size_t count) |
2933 | { | 2931 | { |
2934 | int n; | 2932 | int n; |
2935 | 2933 | ||
@@ -2939,14 +2937,14 @@ static ssize_t sdebug_ptype_store(struct device_driver * ddp, | |||
2939 | } | 2937 | } |
2940 | return -EINVAL; | 2938 | return -EINVAL; |
2941 | } | 2939 | } |
2942 | DRIVER_ATTR(ptype, S_IRUGO | S_IWUSR, sdebug_ptype_show, sdebug_ptype_store); | 2940 | static DRIVER_ATTR_RW(ptype); |
2943 | 2941 | ||
2944 | static ssize_t sdebug_dsense_show(struct device_driver * ddp, char * buf) | 2942 | static ssize_t dsense_show(struct device_driver *ddp, char *buf) |
2945 | { | 2943 | { |
2946 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dsense); | 2944 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dsense); |
2947 | } | 2945 | } |
2948 | static ssize_t sdebug_dsense_store(struct device_driver * ddp, | 2946 | static ssize_t dsense_store(struct device_driver *ddp, const char *buf, |
2949 | const char * buf, size_t count) | 2947 | size_t count) |
2950 | { | 2948 | { |
2951 | int n; | 2949 | int n; |
2952 | 2950 | ||
@@ -2956,15 +2954,14 @@ static ssize_t sdebug_dsense_store(struct device_driver * ddp, | |||
2956 | } | 2954 | } |
2957 | return -EINVAL; | 2955 | return -EINVAL; |
2958 | } | 2956 | } |
2959 | DRIVER_ATTR(dsense, S_IRUGO | S_IWUSR, sdebug_dsense_show, | 2957 | static DRIVER_ATTR_RW(dsense); |
2960 | sdebug_dsense_store); | ||
2961 | 2958 | ||
2962 | static ssize_t sdebug_fake_rw_show(struct device_driver * ddp, char * buf) | 2959 | static ssize_t fake_rw_show(struct device_driver *ddp, char *buf) |
2963 | { | 2960 | { |
2964 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_fake_rw); | 2961 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_fake_rw); |
2965 | } | 2962 | } |
2966 | static ssize_t sdebug_fake_rw_store(struct device_driver * ddp, | 2963 | static ssize_t fake_rw_store(struct device_driver *ddp, const char *buf, |
2967 | const char * buf, size_t count) | 2964 | size_t count) |
2968 | { | 2965 | { |
2969 | int n; | 2966 | int n; |
2970 | 2967 | ||
@@ -2974,15 +2971,14 @@ static ssize_t sdebug_fake_rw_store(struct device_driver * ddp, | |||
2974 | } | 2971 | } |
2975 | return -EINVAL; | 2972 | return -EINVAL; |
2976 | } | 2973 | } |
2977 | DRIVER_ATTR(fake_rw, S_IRUGO | S_IWUSR, sdebug_fake_rw_show, | 2974 | static DRIVER_ATTR_RW(fake_rw); |
2978 | sdebug_fake_rw_store); | ||
2979 | 2975 | ||
2980 | static ssize_t sdebug_no_lun_0_show(struct device_driver * ddp, char * buf) | 2976 | static ssize_t no_lun_0_show(struct device_driver *ddp, char *buf) |
2981 | { | 2977 | { |
2982 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_lun_0); | 2978 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_lun_0); |
2983 | } | 2979 | } |
2984 | static ssize_t sdebug_no_lun_0_store(struct device_driver * ddp, | 2980 | static ssize_t no_lun_0_store(struct device_driver *ddp, const char *buf, |
2985 | const char * buf, size_t count) | 2981 | size_t count) |
2986 | { | 2982 | { |
2987 | int n; | 2983 | int n; |
2988 | 2984 | ||
@@ -2992,15 +2988,14 @@ static ssize_t sdebug_no_lun_0_store(struct device_driver * ddp, | |||
2992 | } | 2988 | } |
2993 | return -EINVAL; | 2989 | return -EINVAL; |
2994 | } | 2990 | } |
2995 | DRIVER_ATTR(no_lun_0, S_IRUGO | S_IWUSR, sdebug_no_lun_0_show, | 2991 | static DRIVER_ATTR_RW(no_lun_0); |
2996 | sdebug_no_lun_0_store); | ||
2997 | 2992 | ||
2998 | static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf) | 2993 | static ssize_t num_tgts_show(struct device_driver *ddp, char *buf) |
2999 | { | 2994 | { |
3000 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); | 2995 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); |
3001 | } | 2996 | } |
3002 | static ssize_t sdebug_num_tgts_store(struct device_driver * ddp, | 2997 | static ssize_t num_tgts_store(struct device_driver *ddp, const char *buf, |
3003 | const char * buf, size_t count) | 2998 | size_t count) |
3004 | { | 2999 | { |
3005 | int n; | 3000 | int n; |
3006 | 3001 | ||
@@ -3011,27 +3006,26 @@ static ssize_t sdebug_num_tgts_store(struct device_driver * ddp, | |||
3011 | } | 3006 | } |
3012 | return -EINVAL; | 3007 | return -EINVAL; |
3013 | } | 3008 | } |
3014 | DRIVER_ATTR(num_tgts, S_IRUGO | S_IWUSR, sdebug_num_tgts_show, | 3009 | static DRIVER_ATTR_RW(num_tgts); |
3015 | sdebug_num_tgts_store); | ||
3016 | 3010 | ||
3017 | static ssize_t sdebug_dev_size_mb_show(struct device_driver * ddp, char * buf) | 3011 | static ssize_t dev_size_mb_show(struct device_driver *ddp, char *buf) |
3018 | { | 3012 | { |
3019 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dev_size_mb); | 3013 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dev_size_mb); |
3020 | } | 3014 | } |
3021 | DRIVER_ATTR(dev_size_mb, S_IRUGO, sdebug_dev_size_mb_show, NULL); | 3015 | static DRIVER_ATTR_RO(dev_size_mb); |
3022 | 3016 | ||
3023 | static ssize_t sdebug_num_parts_show(struct device_driver * ddp, char * buf) | 3017 | static ssize_t num_parts_show(struct device_driver *ddp, char *buf) |
3024 | { | 3018 | { |
3025 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_parts); | 3019 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_parts); |
3026 | } | 3020 | } |
3027 | DRIVER_ATTR(num_parts, S_IRUGO, sdebug_num_parts_show, NULL); | 3021 | static DRIVER_ATTR_RO(num_parts); |
3028 | 3022 | ||
3029 | static ssize_t sdebug_every_nth_show(struct device_driver * ddp, char * buf) | 3023 | static ssize_t every_nth_show(struct device_driver *ddp, char *buf) |
3030 | { | 3024 | { |
3031 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_every_nth); | 3025 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_every_nth); |
3032 | } | 3026 | } |
3033 | static ssize_t sdebug_every_nth_store(struct device_driver * ddp, | 3027 | static ssize_t every_nth_store(struct device_driver *ddp, const char *buf, |
3034 | const char * buf, size_t count) | 3028 | size_t count) |
3035 | { | 3029 | { |
3036 | int nth; | 3030 | int nth; |
3037 | 3031 | ||
@@ -3042,15 +3036,14 @@ static ssize_t sdebug_every_nth_store(struct device_driver * ddp, | |||
3042 | } | 3036 | } |
3043 | return -EINVAL; | 3037 | return -EINVAL; |
3044 | } | 3038 | } |
3045 | DRIVER_ATTR(every_nth, S_IRUGO | S_IWUSR, sdebug_every_nth_show, | 3039 | static DRIVER_ATTR_RW(every_nth); |
3046 | sdebug_every_nth_store); | ||
3047 | 3040 | ||
3048 | static ssize_t sdebug_max_luns_show(struct device_driver * ddp, char * buf) | 3041 | static ssize_t max_luns_show(struct device_driver *ddp, char *buf) |
3049 | { | 3042 | { |
3050 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_luns); | 3043 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_luns); |
3051 | } | 3044 | } |
3052 | static ssize_t sdebug_max_luns_store(struct device_driver * ddp, | 3045 | static ssize_t max_luns_store(struct device_driver *ddp, const char *buf, |
3053 | const char * buf, size_t count) | 3046 | size_t count) |
3054 | { | 3047 | { |
3055 | int n; | 3048 | int n; |
3056 | 3049 | ||
@@ -3061,15 +3054,14 @@ static ssize_t sdebug_max_luns_store(struct device_driver * ddp, | |||
3061 | } | 3054 | } |
3062 | return -EINVAL; | 3055 | return -EINVAL; |
3063 | } | 3056 | } |
3064 | DRIVER_ATTR(max_luns, S_IRUGO | S_IWUSR, sdebug_max_luns_show, | 3057 | static DRIVER_ATTR_RW(max_luns); |
3065 | sdebug_max_luns_store); | ||
3066 | 3058 | ||
3067 | static ssize_t sdebug_max_queue_show(struct device_driver * ddp, char * buf) | 3059 | static ssize_t max_queue_show(struct device_driver *ddp, char *buf) |
3068 | { | 3060 | { |
3069 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_queue); | 3061 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_max_queue); |
3070 | } | 3062 | } |
3071 | static ssize_t sdebug_max_queue_store(struct device_driver * ddp, | 3063 | static ssize_t max_queue_store(struct device_driver *ddp, const char *buf, |
3072 | const char * buf, size_t count) | 3064 | size_t count) |
3073 | { | 3065 | { |
3074 | int n; | 3066 | int n; |
3075 | 3067 | ||
@@ -3080,27 +3072,26 @@ static ssize_t sdebug_max_queue_store(struct device_driver * ddp, | |||
3080 | } | 3072 | } |
3081 | return -EINVAL; | 3073 | return -EINVAL; |
3082 | } | 3074 | } |
3083 | DRIVER_ATTR(max_queue, S_IRUGO | S_IWUSR, sdebug_max_queue_show, | 3075 | static DRIVER_ATTR_RW(max_queue); |
3084 | sdebug_max_queue_store); | ||
3085 | 3076 | ||
3086 | static ssize_t sdebug_no_uld_show(struct device_driver * ddp, char * buf) | 3077 | static ssize_t no_uld_show(struct device_driver *ddp, char *buf) |
3087 | { | 3078 | { |
3088 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_uld); | 3079 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_uld); |
3089 | } | 3080 | } |
3090 | DRIVER_ATTR(no_uld, S_IRUGO, sdebug_no_uld_show, NULL); | 3081 | static DRIVER_ATTR_RO(no_uld); |
3091 | 3082 | ||
3092 | static ssize_t sdebug_scsi_level_show(struct device_driver * ddp, char * buf) | 3083 | static ssize_t scsi_level_show(struct device_driver *ddp, char *buf) |
3093 | { | 3084 | { |
3094 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_scsi_level); | 3085 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_scsi_level); |
3095 | } | 3086 | } |
3096 | DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL); | 3087 | static DRIVER_ATTR_RO(scsi_level); |
3097 | 3088 | ||
3098 | static ssize_t sdebug_virtual_gb_show(struct device_driver * ddp, char * buf) | 3089 | static ssize_t virtual_gb_show(struct device_driver *ddp, char *buf) |
3099 | { | 3090 | { |
3100 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_virtual_gb); | 3091 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_virtual_gb); |
3101 | } | 3092 | } |
3102 | static ssize_t sdebug_virtual_gb_store(struct device_driver * ddp, | 3093 | static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf, |
3103 | const char * buf, size_t count) | 3094 | size_t count) |
3104 | { | 3095 | { |
3105 | int n; | 3096 | int n; |
3106 | 3097 | ||
@@ -3113,16 +3104,15 @@ static ssize_t sdebug_virtual_gb_store(struct device_driver * ddp, | |||
3113 | } | 3104 | } |
3114 | return -EINVAL; | 3105 | return -EINVAL; |
3115 | } | 3106 | } |
3116 | DRIVER_ATTR(virtual_gb, S_IRUGO | S_IWUSR, sdebug_virtual_gb_show, | 3107 | static DRIVER_ATTR_RW(virtual_gb); |
3117 | sdebug_virtual_gb_store); | ||
3118 | 3108 | ||
3119 | static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf) | 3109 | static ssize_t add_host_show(struct device_driver *ddp, char *buf) |
3120 | { | 3110 | { |
3121 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); | 3111 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); |
3122 | } | 3112 | } |
3123 | 3113 | ||
3124 | static ssize_t sdebug_add_host_store(struct device_driver * ddp, | 3114 | static ssize_t add_host_store(struct device_driver *ddp, const char *buf, |
3125 | const char * buf, size_t count) | 3115 | size_t count) |
3126 | { | 3116 | { |
3127 | int delta_hosts; | 3117 | int delta_hosts; |
3128 | 3118 | ||
@@ -3139,16 +3129,14 @@ static ssize_t sdebug_add_host_store(struct device_driver * ddp, | |||
3139 | } | 3129 | } |
3140 | return count; | 3130 | return count; |
3141 | } | 3131 | } |
3142 | DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show, | 3132 | static DRIVER_ATTR_RW(add_host); |
3143 | sdebug_add_host_store); | ||
3144 | 3133 | ||
3145 | static ssize_t sdebug_vpd_use_hostno_show(struct device_driver * ddp, | 3134 | static ssize_t vpd_use_hostno_show(struct device_driver *ddp, char *buf) |
3146 | char * buf) | ||
3147 | { | 3135 | { |
3148 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_vpd_use_hostno); | 3136 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_vpd_use_hostno); |
3149 | } | 3137 | } |
3150 | static ssize_t sdebug_vpd_use_hostno_store(struct device_driver * ddp, | 3138 | static ssize_t vpd_use_hostno_store(struct device_driver *ddp, const char *buf, |
3151 | const char * buf, size_t count) | 3139 | size_t count) |
3152 | { | 3140 | { |
3153 | int n; | 3141 | int n; |
3154 | 3142 | ||
@@ -3158,40 +3146,39 @@ static ssize_t sdebug_vpd_use_hostno_store(struct device_driver * ddp, | |||
3158 | } | 3146 | } |
3159 | return -EINVAL; | 3147 | return -EINVAL; |
3160 | } | 3148 | } |
3161 | DRIVER_ATTR(vpd_use_hostno, S_IRUGO | S_IWUSR, sdebug_vpd_use_hostno_show, | 3149 | static DRIVER_ATTR_RW(vpd_use_hostno); |
3162 | sdebug_vpd_use_hostno_store); | ||
3163 | 3150 | ||
3164 | static ssize_t sdebug_sector_size_show(struct device_driver * ddp, char * buf) | 3151 | static ssize_t sector_size_show(struct device_driver *ddp, char *buf) |
3165 | { | 3152 | { |
3166 | return scnprintf(buf, PAGE_SIZE, "%u\n", scsi_debug_sector_size); | 3153 | return scnprintf(buf, PAGE_SIZE, "%u\n", scsi_debug_sector_size); |
3167 | } | 3154 | } |
3168 | DRIVER_ATTR(sector_size, S_IRUGO, sdebug_sector_size_show, NULL); | 3155 | static DRIVER_ATTR_RO(sector_size); |
3169 | 3156 | ||
3170 | static ssize_t sdebug_dix_show(struct device_driver *ddp, char *buf) | 3157 | static ssize_t dix_show(struct device_driver *ddp, char *buf) |
3171 | { | 3158 | { |
3172 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dix); | 3159 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dix); |
3173 | } | 3160 | } |
3174 | DRIVER_ATTR(dix, S_IRUGO, sdebug_dix_show, NULL); | 3161 | static DRIVER_ATTR_RO(dix); |
3175 | 3162 | ||
3176 | static ssize_t sdebug_dif_show(struct device_driver *ddp, char *buf) | 3163 | static ssize_t dif_show(struct device_driver *ddp, char *buf) |
3177 | { | 3164 | { |
3178 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dif); | 3165 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_dif); |
3179 | } | 3166 | } |
3180 | DRIVER_ATTR(dif, S_IRUGO, sdebug_dif_show, NULL); | 3167 | static DRIVER_ATTR_RO(dif); |
3181 | 3168 | ||
3182 | static ssize_t sdebug_guard_show(struct device_driver *ddp, char *buf) | 3169 | static ssize_t guard_show(struct device_driver *ddp, char *buf) |
3183 | { | 3170 | { |
3184 | return scnprintf(buf, PAGE_SIZE, "%u\n", scsi_debug_guard); | 3171 | return scnprintf(buf, PAGE_SIZE, "%u\n", scsi_debug_guard); |
3185 | } | 3172 | } |
3186 | DRIVER_ATTR(guard, S_IRUGO, sdebug_guard_show, NULL); | 3173 | static DRIVER_ATTR_RO(guard); |
3187 | 3174 | ||
3188 | static ssize_t sdebug_ato_show(struct device_driver *ddp, char *buf) | 3175 | static ssize_t ato_show(struct device_driver *ddp, char *buf) |
3189 | { | 3176 | { |
3190 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_ato); | 3177 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_ato); |
3191 | } | 3178 | } |
3192 | DRIVER_ATTR(ato, S_IRUGO, sdebug_ato_show, NULL); | 3179 | static DRIVER_ATTR_RO(ato); |
3193 | 3180 | ||
3194 | static ssize_t sdebug_map_show(struct device_driver *ddp, char *buf) | 3181 | static ssize_t map_show(struct device_driver *ddp, char *buf) |
3195 | { | 3182 | { |
3196 | ssize_t count; | 3183 | ssize_t count; |
3197 | 3184 | ||
@@ -3206,15 +3193,14 @@ static ssize_t sdebug_map_show(struct device_driver *ddp, char *buf) | |||
3206 | 3193 | ||
3207 | return count; | 3194 | return count; |
3208 | } | 3195 | } |
3209 | DRIVER_ATTR(map, S_IRUGO, sdebug_map_show, NULL); | 3196 | static DRIVER_ATTR_RO(map); |
3210 | 3197 | ||
3211 | static ssize_t sdebug_removable_show(struct device_driver *ddp, | 3198 | static ssize_t removable_show(struct device_driver *ddp, char *buf) |
3212 | char *buf) | ||
3213 | { | 3199 | { |
3214 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_removable ? 1 : 0); | 3200 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_removable ? 1 : 0); |
3215 | } | 3201 | } |
3216 | static ssize_t sdebug_removable_store(struct device_driver *ddp, | 3202 | static ssize_t removable_store(struct device_driver *ddp, const char *buf, |
3217 | const char *buf, size_t count) | 3203 | size_t count) |
3218 | { | 3204 | { |
3219 | int n; | 3205 | int n; |
3220 | 3206 | ||
@@ -3224,74 +3210,43 @@ static ssize_t sdebug_removable_store(struct device_driver *ddp, | |||
3224 | } | 3210 | } |
3225 | return -EINVAL; | 3211 | return -EINVAL; |
3226 | } | 3212 | } |
3227 | DRIVER_ATTR(removable, S_IRUGO | S_IWUSR, sdebug_removable_show, | 3213 | static DRIVER_ATTR_RW(removable); |
3228 | sdebug_removable_store); | ||
3229 | 3214 | ||
3230 | 3215 | /* Note: The following array creates attribute files in the | |
3231 | /* Note: The following function creates attribute files in the | ||
3232 | /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these | 3216 | /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these |
3233 | files (over those found in the /sys/module/scsi_debug/parameters | 3217 | files (over those found in the /sys/module/scsi_debug/parameters |
3234 | directory) is that auxiliary actions can be triggered when an attribute | 3218 | directory) is that auxiliary actions can be triggered when an attribute |
3235 | is changed. For example see: sdebug_add_host_store() above. | 3219 | is changed. For example see: sdebug_add_host_store() above. |
3236 | */ | 3220 | */ |
3237 | static int do_create_driverfs_files(void) | ||
3238 | { | ||
3239 | int ret; | ||
3240 | 3221 | ||
3241 | ret = driver_create_file(&sdebug_driverfs_driver, &driver_attr_add_host); | 3222 | static struct attribute *sdebug_drv_attrs[] = { |
3242 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_delay); | 3223 | &driver_attr_delay.attr, |
3243 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); | 3224 | &driver_attr_opts.attr, |
3244 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dsense); | 3225 | &driver_attr_ptype.attr, |
3245 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_every_nth); | 3226 | &driver_attr_dsense.attr, |
3246 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_fake_rw); | 3227 | &driver_attr_fake_rw.attr, |
3247 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_max_luns); | 3228 | &driver_attr_no_lun_0.attr, |
3248 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_max_queue); | 3229 | &driver_attr_num_tgts.attr, |
3249 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_no_lun_0); | 3230 | &driver_attr_dev_size_mb.attr, |
3250 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_no_uld); | 3231 | &driver_attr_num_parts.attr, |
3251 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_parts); | 3232 | &driver_attr_every_nth.attr, |
3252 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); | 3233 | &driver_attr_max_luns.attr, |
3253 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_ptype); | 3234 | &driver_attr_max_queue.attr, |
3254 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts); | 3235 | &driver_attr_no_uld.attr, |
3255 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_removable); | 3236 | &driver_attr_scsi_level.attr, |
3256 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); | 3237 | &driver_attr_virtual_gb.attr, |
3257 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_virtual_gb); | 3238 | &driver_attr_add_host.attr, |
3258 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_vpd_use_hostno); | 3239 | &driver_attr_vpd_use_hostno.attr, |
3259 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_sector_size); | 3240 | &driver_attr_sector_size.attr, |
3260 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dix); | 3241 | &driver_attr_dix.attr, |
3261 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dif); | 3242 | &driver_attr_dif.attr, |
3262 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_guard); | 3243 | &driver_attr_guard.attr, |
3263 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_ato); | 3244 | &driver_attr_ato.attr, |
3264 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_map); | 3245 | &driver_attr_map.attr, |
3265 | return ret; | 3246 | &driver_attr_removable.attr, |
3266 | } | 3247 | NULL, |
3267 | 3248 | }; | |
3268 | static void do_remove_driverfs_files(void) | 3249 | ATTRIBUTE_GROUPS(sdebug_drv); |
3269 | { | ||
3270 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_map); | ||
3271 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_ato); | ||
3272 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_guard); | ||
3273 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dif); | ||
3274 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dix); | ||
3275 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_sector_size); | ||
3276 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_vpd_use_hostno); | ||
3277 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_virtual_gb); | ||
3278 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); | ||
3279 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_opts); | ||
3280 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_ptype); | ||
3281 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_removable); | ||
3282 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); | ||
3283 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_parts); | ||
3284 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_no_uld); | ||
3285 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_no_lun_0); | ||
3286 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_max_queue); | ||
3287 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_max_luns); | ||
3288 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_fake_rw); | ||
3289 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_every_nth); | ||
3290 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dsense); | ||
3291 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); | ||
3292 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_delay); | ||
3293 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_add_host); | ||
3294 | } | ||
3295 | 3250 | ||
3296 | struct device *pseudo_primary; | 3251 | struct device *pseudo_primary; |
3297 | 3252 | ||
@@ -3456,12 +3411,6 @@ static int __init scsi_debug_init(void) | |||
3456 | ret); | 3411 | ret); |
3457 | goto bus_unreg; | 3412 | goto bus_unreg; |
3458 | } | 3413 | } |
3459 | ret = do_create_driverfs_files(); | ||
3460 | if (ret < 0) { | ||
3461 | printk(KERN_WARNING "scsi_debug: driver_create_file error: %d\n", | ||
3462 | ret); | ||
3463 | goto del_files; | ||
3464 | } | ||
3465 | 3414 | ||
3466 | init_all_queued(); | 3415 | init_all_queued(); |
3467 | 3416 | ||
@@ -3482,9 +3431,6 @@ static int __init scsi_debug_init(void) | |||
3482 | } | 3431 | } |
3483 | return 0; | 3432 | return 0; |
3484 | 3433 | ||
3485 | del_files: | ||
3486 | do_remove_driverfs_files(); | ||
3487 | driver_unregister(&sdebug_driverfs_driver); | ||
3488 | bus_unreg: | 3434 | bus_unreg: |
3489 | bus_unregister(&pseudo_lld_bus); | 3435 | bus_unregister(&pseudo_lld_bus); |
3490 | dev_unreg: | 3436 | dev_unreg: |
@@ -3506,7 +3452,6 @@ static void __exit scsi_debug_exit(void) | |||
3506 | stop_all_queued(); | 3452 | stop_all_queued(); |
3507 | for (; k; k--) | 3453 | for (; k; k--) |
3508 | sdebug_remove_adapter(); | 3454 | sdebug_remove_adapter(); |
3509 | do_remove_driverfs_files(); | ||
3510 | driver_unregister(&sdebug_driverfs_driver); | 3455 | driver_unregister(&sdebug_driverfs_driver); |
3511 | bus_unregister(&pseudo_lld_bus); | 3456 | bus_unregister(&pseudo_lld_bus); |
3512 | root_device_unregister(pseudo_primary); | 3457 | root_device_unregister(pseudo_primary); |
@@ -4096,4 +4041,5 @@ static struct bus_type pseudo_lld_bus = { | |||
4096 | .match = pseudo_lld_bus_match, | 4041 | .match = pseudo_lld_bus_match, |
4097 | .probe = sdebug_driver_probe, | 4042 | .probe = sdebug_driver_probe, |
4098 | .remove = sdebug_driver_remove, | 4043 | .remove = sdebug_driver_remove, |
4044 | .drv_groups = sdebug_drv_groups, | ||
4099 | }; | 4045 | }; |