diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2012-09-06 06:04:33 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2012-09-24 04:11:05 -0400 |
commit | d986788b2653ef76441c6b6ba1787164546735a6 (patch) | |
tree | c7b84c1ebb9a5319c573ecd3c0eb744f81fc3d81 /drivers/scsi/scsi_debug.c | |
parent | eafcde2103a2bfe27304664f331b10265d8e7bca (diff) |
[SCSI] scsi_debug: Add "removable" parameter
Add "removable" module parameter to set the "removable" attribute of any
subsequently created debug block device. It is a writable driver option, so
that you can switch between removable and "fixed" media block devices in
between the add_host calls.
This is useful for being able to test the different behaviour/required
privileges in e. g. the udisks test suite.
Signed-off-by: Martin Pitt <martin.pitt@ubuntu.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 | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 182d5a57ab74..57fbd5a3d4e2 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c | |||
@@ -109,6 +109,7 @@ static const char * scsi_debug_version_date = "20100324"; | |||
109 | #define DEF_OPT_BLKS 64 | 109 | #define DEF_OPT_BLKS 64 |
110 | #define DEF_PHYSBLK_EXP 0 | 110 | #define DEF_PHYSBLK_EXP 0 |
111 | #define DEF_PTYPE 0 | 111 | #define DEF_PTYPE 0 |
112 | #define DEF_REMOVABLE false | ||
112 | #define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */ | 113 | #define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */ |
113 | #define DEF_SECTOR_SIZE 512 | 114 | #define DEF_SECTOR_SIZE 512 |
114 | #define DEF_UNMAP_ALIGNMENT 0 | 115 | #define DEF_UNMAP_ALIGNMENT 0 |
@@ -193,11 +194,11 @@ static unsigned int scsi_debug_unmap_granularity = DEF_UNMAP_GRANULARITY; | |||
193 | static unsigned int scsi_debug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; | 194 | static unsigned int scsi_debug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; |
194 | static unsigned int scsi_debug_unmap_max_desc = DEF_UNMAP_MAX_DESC; | 195 | static unsigned int scsi_debug_unmap_max_desc = DEF_UNMAP_MAX_DESC; |
195 | static unsigned int scsi_debug_write_same_length = DEF_WRITESAME_LENGTH; | 196 | static unsigned int scsi_debug_write_same_length = DEF_WRITESAME_LENGTH; |
197 | static bool scsi_debug_removable = DEF_REMOVABLE; | ||
196 | 198 | ||
197 | static int scsi_debug_cmnd_count = 0; | 199 | static int scsi_debug_cmnd_count = 0; |
198 | 200 | ||
199 | #define DEV_READONLY(TGT) (0) | 201 | #define DEV_READONLY(TGT) (0) |
200 | #define DEV_REMOVEABLE(TGT) (0) | ||
201 | 202 | ||
202 | static unsigned int sdebug_store_sectors; | 203 | static unsigned int sdebug_store_sectors; |
203 | static sector_t sdebug_capacity; /* in sectors */ | 204 | static sector_t sdebug_capacity; /* in sectors */ |
@@ -919,7 +920,7 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target, | |||
919 | return ret; | 920 | return ret; |
920 | } | 921 | } |
921 | /* drops through here for a standard inquiry */ | 922 | /* drops through here for a standard inquiry */ |
922 | arr[1] = DEV_REMOVEABLE(target) ? 0x80 : 0; /* Removable disk */ | 923 | arr[1] = scsi_debug_removable ? 0x80 : 0; /* Removable disk */ |
923 | arr[2] = scsi_debug_scsi_level; | 924 | arr[2] = scsi_debug_scsi_level; |
924 | arr[3] = 2; /* response_data_format==2 */ | 925 | arr[3] = 2; /* response_data_format==2 */ |
925 | arr[4] = SDEBUG_LONG_INQ_SZ - 5; | 926 | arr[4] = SDEBUG_LONG_INQ_SZ - 5; |
@@ -1211,7 +1212,7 @@ static int resp_format_pg(unsigned char * p, int pcontrol, int target) | |||
1211 | p[11] = sdebug_sectors_per & 0xff; | 1212 | p[11] = sdebug_sectors_per & 0xff; |
1212 | p[12] = (scsi_debug_sector_size >> 8) & 0xff; | 1213 | p[12] = (scsi_debug_sector_size >> 8) & 0xff; |
1213 | p[13] = scsi_debug_sector_size & 0xff; | 1214 | p[13] = scsi_debug_sector_size & 0xff; |
1214 | if (DEV_REMOVEABLE(target)) | 1215 | if (scsi_debug_removable) |
1215 | p[20] |= 0x20; /* should agree with INQUIRY */ | 1216 | p[20] |= 0x20; /* should agree with INQUIRY */ |
1216 | if (1 == pcontrol) | 1217 | if (1 == pcontrol) |
1217 | memset(p + 2, 0, sizeof(format_pg) - 2); | 1218 | memset(p + 2, 0, sizeof(format_pg) - 2); |
@@ -2754,6 +2755,7 @@ module_param_named(opt_blks, scsi_debug_opt_blks, int, S_IRUGO); | |||
2754 | module_param_named(opts, scsi_debug_opts, int, S_IRUGO | S_IWUSR); | 2755 | module_param_named(opts, scsi_debug_opts, int, S_IRUGO | S_IWUSR); |
2755 | module_param_named(physblk_exp, scsi_debug_physblk_exp, int, S_IRUGO); | 2756 | module_param_named(physblk_exp, scsi_debug_physblk_exp, int, S_IRUGO); |
2756 | module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR); | 2757 | module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR); |
2758 | module_param_named(removable, scsi_debug_removable, bool, S_IRUGO | S_IWUSR); | ||
2757 | module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO); | 2759 | module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO); |
2758 | module_param_named(sector_size, scsi_debug_sector_size, int, S_IRUGO); | 2760 | module_param_named(sector_size, scsi_debug_sector_size, int, S_IRUGO); |
2759 | module_param_named(unmap_alignment, scsi_debug_unmap_alignment, int, S_IRUGO); | 2761 | module_param_named(unmap_alignment, scsi_debug_unmap_alignment, int, S_IRUGO); |
@@ -2796,6 +2798,7 @@ MODULE_PARM_DESC(opt_blks, "optimal transfer length in block (def=64)"); | |||
2796 | MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)"); | 2798 | MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)"); |
2797 | MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)"); | 2799 | MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)"); |
2798 | MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); | 2800 | MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); |
2801 | MODULE_PARM_DESC(removable, "claim to have removable media (def=0)"); | ||
2799 | MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); | 2802 | MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); |
2800 | MODULE_PARM_DESC(sector_size, "logical block size in bytes (def=512)"); | 2803 | MODULE_PARM_DESC(sector_size, "logical block size in bytes (def=512)"); |
2801 | MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)"); | 2804 | MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)"); |
@@ -3205,6 +3208,25 @@ static ssize_t sdebug_map_show(struct device_driver *ddp, char *buf) | |||
3205 | } | 3208 | } |
3206 | DRIVER_ATTR(map, S_IRUGO, sdebug_map_show, NULL); | 3209 | DRIVER_ATTR(map, S_IRUGO, sdebug_map_show, NULL); |
3207 | 3210 | ||
3211 | static ssize_t sdebug_removable_show(struct device_driver *ddp, | ||
3212 | char *buf) | ||
3213 | { | ||
3214 | return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_removable ? 1 : 0); | ||
3215 | } | ||
3216 | static ssize_t sdebug_removable_store(struct device_driver *ddp, | ||
3217 | const char *buf, size_t count) | ||
3218 | { | ||
3219 | int n; | ||
3220 | |||
3221 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { | ||
3222 | scsi_debug_removable = (n > 0); | ||
3223 | return count; | ||
3224 | } | ||
3225 | return -EINVAL; | ||
3226 | } | ||
3227 | DRIVER_ATTR(removable, S_IRUGO | S_IWUSR, sdebug_removable_show, | ||
3228 | sdebug_removable_store); | ||
3229 | |||
3208 | 3230 | ||
3209 | /* Note: The following function creates attribute files in the | 3231 | /* Note: The following function creates attribute files in the |
3210 | /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these | 3232 | /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these |
@@ -3230,6 +3252,7 @@ static int do_create_driverfs_files(void) | |||
3230 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); | 3252 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); |
3231 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_ptype); | 3253 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_ptype); |
3232 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts); | 3254 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts); |
3255 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_removable); | ||
3233 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); | 3256 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); |
3234 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_virtual_gb); | 3257 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_virtual_gb); |
3235 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_vpd_use_hostno); | 3258 | ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_vpd_use_hostno); |
@@ -3255,6 +3278,7 @@ static void do_remove_driverfs_files(void) | |||
3255 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); | 3278 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); |
3256 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_opts); | 3279 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_opts); |
3257 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_ptype); | 3280 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_ptype); |
3281 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_removable); | ||
3258 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); | 3282 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); |
3259 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_parts); | 3283 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_num_parts); |
3260 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_no_uld); | 3284 | driver_remove_file(&sdebug_driverfs_driver, &driver_attr_no_uld); |