scsi_debug: Make CRC_T10DIF support optional
PATCH v2 1/1 scsi_debug: Make CRC_T10DIF support optional
Not all scsi_debug users need data integrity support. Hence modify the scsi_debug driver such that it becomes possible to build this driver without data integrity support. The changes in this patch are as follows:
- Split the scsi_debug source code into two files without modifying any functionality.
- Instead of selecting CRC_T10DIF no matter how the scsi_debug driver is built, only select CRC_T10DIF if the scsi_debug driver is built-in to the kernel.
---
Changes compared with v1: made the patch description more detailed.
drivers/scsi/Kconfig | 2 +-
drivers/scsi/Makefile | 2 +
drivers/scsi/scsi_debug-dif.h | 65 +++++
drivers/scsi/scsi_debug_dif.c | 224 +++++++++++++++
.../scsi/{scsi_debug.c => scsi_debug_main.c} | 257 ++----------------
5 files changed, 308 insertions(+), 242 deletions(-)
create mode 100644 drivers/scsi/scsi_debug-dif.h
create mode 100644 drivers/scsi/scsi_debug_dif.c
rename drivers/scsi/{scsi_debug.c => scsi_debug_main.c} (97%)drivers/scsi/Kconfig +1 -1
@@ -1227,7 +1227,7 @@ config SCSI_WD719X config SCSI_DEBUG tristate "SCSI debugging host and device simulator" depends on SCSI - select CRC_T10DIF + select CRC_T10DIF if SCSI_DEBUG = y help This pseudo driver simulates one or more hosts (SCSI initiators), each with one or more targets, each with one or more logical units.
drivers/scsi/Makefile +2 -0
@@ -156,6 +156,8 @@ obj-$(CONFIG_SCSI_HISI_SAS) += hisi_sas/ # This goes last, so that "real" scsi devices probe earlier obj-$(CONFIG_SCSI_DEBUG) += scsi_debug.o +scsi_debug-y += scsi_debug_main.o +scsi_debug-$(CONFIG_CRC_T10DIF) += scsi_debug_dif.o scsi_mod-y += scsi.o hosts.o scsi_ioctl.o \ scsicam.o scsi_error.o scsi_lib.o scsi_mod-$(CONFIG_SCSI_CONSTANTS) += constants.o
drivers/scsi/scsi_debug-dif.h new file +65 -0
65 lines not on this page · raw message
drivers/scsi/scsi_debug_dif.c new file +224 -0
224 lines not on this page · raw message
drivers/scsi/scsi_debug_main.c renamed from drivers/scsi/scsi_debug.c +16 -241
359 lines not on this page · raw message
Quoted 14 lines · Bart Van Assche
Not all
scsi_debugusers need data integrity support. Hence modify thescsi_debugdriver such that it becomes possible to build this driver without data integrity support. The changes in this patch are as follows:
- Split thescsi_debugsource code into two files without modifying any functionality.
- Instead of selectingCRC_T10DIFno matter how thescsi_debugdriver is built, only selectCRC_T10DIFif thescsi_debugdriver is built-in to the kernel.Cc Douglas Gilbert <[email protected]>Cc John Garry <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Quoted 8 lines
---
Changes compared with v1: made the patch description more detailed.
drivers/scsi/Kconfig | 2 +- drivers/scsi/Makefile | 2 + drivers/scsi/scsi_debug-dif.h | 65 +++++ drivers/scsi/scsi_debug_dif.c | 224 +++++++++++++++
inconsistent filename format: scsi_debug-dif.c vs scsi_debug_dif.h - is that intentional?
Quoted 11 lines
.../scsi/{scsi_debug.c => scsi_debug_main.c} | 257 ++---------------- 5 files changed, 308 insertions(+), 242 deletions(-)create mode 100644
drivers/scsi/scsi_debug-dif.hcreate mode 100644drivers/scsi/scsi_debug_dif.crenamedrivers/scsi/{scsi_debug.c=>scsi_debug_main.c} (97%)drivers/scsi/Kconfig +0
-0
drivers/scsi/Kconfig config SCSI_WD719X · line 1230
Quoted 5 lines
drivers/scsi/Kconfig +1
-1@@ -1227,7 +1227,7 @@ config SCSI_WD719X config SCSI_DEBUG tristate "SCSI debugging host and device simulator" depends on SCSI - select CRC_T10DIF + select CRC_T10DIF if SCSI_DEBUG = y
Do we really need to select at all now? What does this buy us? Preference is generally not to use select.
Quoted 22 lines
drivers/scsi/Kconfig +0
-0help This pseudo driver simulates one or more hosts (SCSI initiators), each with one or more targets, each with one or more logical units.drivers/scsi/Makefile +2
-0@@ -156,6 +156,8 @@ obj-$(CONFIG_SCSI_HISI_SAS) += hisi_sas/ # This goes last, so that "real" scsi devices probe earlier obj-$(CONFIG_SCSI_DEBUG) += scsi_debug.o +scsi_debug-y += scsi_debug_main.o +scsi_debug-$(CONFIG_CRC_T10DIF) += scsi_debug_dif.o scsi_mod-y += scsi.o hosts.o scsi_ioctl.o \ scsicam.o scsi_error.o scsi_lib.o scsi_mod-$(CONFIG_SCSI_CONSTANTS) += constants.odrivers/scsi/scsi_debug-dif.h new file +0
-0
drivers/scsi/scsi_debug-dif.h line 9
Quoted 9 lines
drivers/scsi/scsi_debug-dif.h new file +9
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SCSI_DEBUG_DIF_H +#define _SCSI_DEBUG_DIF_H + +#include <linux/kconfig.h> +#include <linux/types.h> +#include <linux/spinlock_types.h> + +struct scsi_cmnd ;
Do you really need to have a prototype for this? I'm a bit in shock seeing this in a scsi low-level driver.
drivers/scsi/scsi_debug-dif.h line 10
Quoted 1 line
drivers/scsi/scsi_debug-dif.h new file +1
-0+struct sdebug_dev_info ;
How is this specific to dif? This should be defined in a common header file if used by both scsi_debug_main.c and scsi_debug_dif.c
drivers/scsi/scsi_debug-dif.h line 13
Quoted 3 lines
drivers/scsi/scsi_debug-dif.h new file +3
-0+struct t10_pi_tuple ; + +extern int dix_writes;
For whos benefit is this in a dif header file?
dix_writes is defined in main.c, so surely this extern needs to be in scsi_debug_dif.c or a common header
For me, I would actually just declare this in scsi_debug_dif.c and have scsi_debug_dif_get_dix_writes() or similar to return this value. This function would be stubbed for CONFIG_CRC_T10DIF=n
drivers/scsi/scsi_debug-dif.h line 21
Quoted 8 lines
drivers/scsi/scsi_debug-dif.h new file +8
-0+extern int dix_reads; +extern int dif_errors; +extern struct xarray *const per_store_ap; +extern int sdebug_dif; +extern int sdebug_dix; +extern unsigned int sdebug_guard; +extern int sdebug_sector_size; +extern unsigned int sdebug_store_sectors;
I doubt why all these are here
drivers/scsi/scsi_debug-dif.h line 24
Quoted 3 lines
drivers/scsi/scsi_debug-dif.h new file +3
-0+ +/* There is an xarray of pointers to this struct's objects, one per host */ +struct sdeb_store_info {
this is not specific to dif, yet in a dif header
drivers/scsi/scsi_debug-dif.h line 37
Quoted 13 lines
drivers/scsi/scsi_debug-dif.h new file +13
-0+rwlock_t macc_lck;/* for atomic media access on this store */ +u8 *storep;/* user data storage (ram) */ +struct t10_pi_tuple *dif_storep;/* protection info */ +void *map_storep;/* provisioning map */ +}; + +struct sdeb_store_info *devip2sip (struct sdebug_dev_info *devip, +bool bug_if_fake_rw); + +#if IS_ENABLED (CONFIG_CRC_T10DIF ) + +int dif_verify (struct t10_pi_tuple *sdt,const void *data,sector_t sector, +u32 ei_lba);
Is this actually used in main.c?
I do also notice that we have chunks of code in main.c that does PI checking, like in resp_write_scat() - surely dif stuff should be in dif.c now
drivers/scsi/scsi_debug-dif.h line 48
Quoted 11 lines
drivers/scsi/scsi_debug-dif.h new file +11
-0+int prot_verify_read (struct scsi_cmnd *scp,sector_t start_sec, +unsigned int sectors,u32 ei_lba); +int prot_verify_write (struct scsi_cmnd *SCpnt,sector_t start_sec, +unsigned int sectors,u32 ei_lba); + +#else /* CONFIG_CRC_T10DIF */ + +static inline int dif_verify (struct t10_pi_tuple *sdt,const void *data, +sector_t sector,u32 ei_lba) +{ +return 0x01 ;/*GUARD check failed*/
leave space before and after /* and */
Quoted 23 lines
drivers/scsi/scsi_debug-dif.h new file +17
-0+} + +static inline int prot_verify_read (struct scsi_cmnd *scp,sector_t start_sec, +unsigned int sectors,u32 ei_lba) +{ +return 0x01 ;/*GUARD check failed*/ +} + +static inline int prot_verify_write (struct scsi_cmnd *SCpnt,sector_t start_sec, +unsigned int sectors,u32 ei_lba) +{ +return 0x01 ;/*GUARD check failed*/ +} + +#endif /* CONFIG_CRC_T10DIF */ + +#endif /* _SCSI_DEBUG_DIF_H */ drivers/scsi/scsi_debug_dif.c new file +0
-0
drivers/scsi/scsi_debug_dif.c line 2
Quoted 2 lines
drivers/scsi/scsi_debug_dif.c new file +2
-0@@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include "scsi_debug-dif.h"
I always find it is strange to include driver proprietary header files before common header files - I guess that is why the scsi_cmnd prototype is declared, above
drivers/scsi/scsi_debug_dif.c line 7
Quoted 5 lines
drivers/scsi/scsi_debug_dif.c new file +5
-0+#include <linux/crc-t10dif.h> +#include <linux/t10-pi.h> +#include <net/checksum.h> +#include <scsi/scsi_cmnd.h> +
Thanks,
John
Quoted 7 lines · John Garry
Quoted 4 lines · Bart Van Assche
drivers/scsi/Kconfig | 2 +- drivers/scsi/Makefile | 2 + drivers/scsi/scsi_debug-dif.h | 65 +++++ drivers/scsi/scsi_debug_dif.c | 224 +++++++++++++++
inconsistent filename format:
scsi_debug-dif.cvsscsi_debug_dif.h- is that intentional?
That should be fixed. Do you perhaps have a preference?
Quoted 6 lines
Quoted 6 lines
.../scsi/{scsi_debug.c=> scsi_debug_main.c} | 257 ++----------------5 files changed, 308 insertions(+), 242 deletions(-)create mode 100644
drivers/scsi/scsi_debug-dif.hcreate mode 100644drivers/scsi/scsi_debug_dif.crenamedrivers/scsi/{scsi_debug.c=>scsi_debug_main.c} (97%)
Quoted 12 lines
Quoted 10 lines
drivers/scsi/Kconfig +0
-0@@ -1227,7 +1227,7 @@ config SCSI_WD719Xconfig
SCSI_DEBUG
tristate "SCSI debugging host and device simulator" depends on SCSI
- selectCRC_T10DIF
+ selectCRC_T10DIFifSCSI_DEBUG= yDo we really need to select at all now? What does this buy us? Preference is generally not to use select.
I want to exclude the CRC_T10DIF = m and SCSI_DEBUG = y combination because it causes the build to fail. I will leave out the select statement and will change "depends on SCSI" into the following:
depends on SCSI && (m || CRC_T10DIF = y)
Quoted 6 lines
Quoted 6 lines
drivers/scsi/scsi_debug-dif.h new file +3
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SCSI_DEBUG_DIF_H +#define _SCSI_DEBUG_DIF_H
Quoted 8 lines
drivers/scsi/scsi_debug-dif.h line 9
Quoted 6 lines
drivers/scsi/scsi_debug-dif.h new file +6
-0+ +#include <linux/kconfig.h> +#include <linux/types.h> +#include <linux/spinlock_types.h> + +struct scsi_cmnd ;Do you really need to have a prototype for this? I'm a bit in shock seeing this in a scsi low-level driver.
I will leave the above out and add "#include <scsi/scsi_cmnd.h>" instead.
Quoted 1 line
dix_writesis defined inmain.c, so surely this extern needs to be inscsi_debug_dif.cor a common header
The scsi_debug-dif.h header file is included from two .c files. Without this header file, the compiler wouldn't be able to check the consistency of the declarations in scsi_debug-dif.h with the definitions in the two scsi_debug .c files.
Quoted 1 line
For me, I would actually just declare this in
scsi_debug_dif.cand havescsi_debug_dif_get_dix_writes()or similar to return this value. This function would be stubbed forCONFIG_CRC_T10DIF=n
My goal is to minimize changes while splitting the scsi_debug source code. Hence the "extern" declaration.
Quoted 10 lines
drivers/scsi/scsi_debug-dif.h line 21
Quoted 8 lines
drivers/scsi/scsi_debug-dif.h new file +8
-0+extern int dix_reads; +extern int dif_errors; +extern struct xarray *const per_store_ap; +extern int sdebug_dif; +extern int sdebug_dix; +extern unsigned int sdebug_guard; +extern int sdebug_sector_size; +extern unsigned int sdebug_store_sectors;I doubt why all these are here
All the variables declared above are used in both scsi_debug_dif.c and scsi_debug_main.c.
Quoted 5 lines
Quoted 3 lines
drivers/scsi/scsi_debug-dif.h new file +1
-0+int dif_verify(struct t10_pi_tuple *sdt, const void *data, sector_tsector,
+ u32ei_lba);Is this actually used in
main.c?
It is not. I will remove it.
Quoted 1 line
I do also notice that we have chunks of code in
main.cthat does PI checking, like inresp_write_scat()- surely dif stuff should be indif.cnow
I'm concerned that moving that code would make resp_write_scat() much less readable. Please note that the code in resp_write_scat() that does PI checking is guarded by an 'if (have_dif_prot)' check and that have_dif_prot = false if CONFIG_CRC_T10DIF=n.
Quoted 7 lines
drivers/scsi/scsi_debug_dif.c line 2
Quoted 5 lines
drivers/scsi/scsi_debug_dif.c new file +2
-0@@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include "scsi_debug-dif.h" I always find it is strange to include driver proprietary header files before common header files - I guess that is why the
scsi_cmndprototype is declared, above
Including driver-private header files first is required by some coding style guides because it causes the build to fail if the driver-private header file does not include all include files it should include. See also
https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes
(I am aware that this style guide does not apply to Linux kernel code).
Thanks,
Bart.
On 06/03/2024 18:27, Bart Van Assche wrote:
As an alternative, what about something like this:
----->8----
drivers/scsi/Kconfig +0 -1
@@ -1227,7 +1227,6 @@ config SCSI_WD719X config SCSI_DEBUG tristate "SCSI debugging host and device simulator" depends on SCSI - select CRC_T10DIF help This pseudo driver simulates one or more hosts (SCSI initiators), each with one or more targets, each with one or more logical units.
drivers/scsi/scsi_debug.c +13 -0
@@ -3471,6 +3471,7 @@ static bool comp_write_worker(struct sdeb_store_info *sip, u64 lba, u32 num,return res; } +#if (IS_ENABLED (CONFIG_CRC_T10DIF ))static __be16 dif_compute_csum (const void *buf,int len) {__be16 csum;
@@ -3509,6 +3510,13 @@ static int dif_verify(struct t10_pi_tuple *sdt, const void *data, }return 0 ; } +#else +static int dif_verify (struct t10_pi_tuple *sdt,const void *data, +sector_t sector,u32 ei_lba) +{ +return -EOPNOTSUPP ; +} +#endif static void dif_copy_prot (struct scsi_cmnd *scp,sector_t sector,unsigned int sectors,bool read)
@@ -7421,7 +7429,12 @@ static int __init scsi_debug_init(void)case T10_PI_TYPE1_PROTECTION :case T10_PI_TYPE2_PROTECTION :case T10_PI_TYPE3_PROTECTION : +#if (IS_ENABLED (CONFIG_CRC_T10DIF )) have_dif_prot = true; +#else +pr_err ("CRC_T10DIF not enabled\n" ); +return -EINVAL ; +#endif break ;default :
----8<-----
I know that IS_ENABLED(CONFIG_XXX)) ain't too nice to use, but this is a lot less change and we also don't need multiple files for the driver. As below, it's not easy to separate the CRC_T10DIF-related stuff out.
Thanks,
John
EOM
Quoted 114 lines · John Garry
Quoted 7 lines · Bart Van Assche
Quoted 4 lines
drivers/scsi/Kconfig | 2 +- drivers/scsi/Makefile | 2 + drivers/scsi/scsi_debug-dif.h | 65 +++++ drivers/scsi/scsi_debug_dif.c | 224 +++++++++++++++
inconsistent filename format:
scsi_debug-dif.cvsscsi_debug_dif.h- is that intentional?That should be fixed. Do you perhaps have a preference?
Quoted 6 lines
Quoted 6 lines
.../scsi/{scsi_debug.c=> scsi_debug_main.c} | 257 ++----------------5 files changed, 308 insertions(+), 242 deletions(-)create mode 100644
drivers/scsi/scsi_debug-dif.hcreate mode 100644drivers/scsi/scsi_debug_dif.crenamedrivers/scsi/{scsi_debug.c=>scsi_debug_main.c} (97%)Quoted 12 lines
Quoted 10 lines
drivers/scsi/Kconfig +0
-0@@ -1227,7 +1227,7 @@ config SCSI_WD719Xconfig
SCSI_DEBUG
tristate "SCSI debugging host and device simulator" depends on SCSI
- selectCRC_T10DIF
+ selectCRC_T10DIFifSCSI_DEBUG= yDo we really need to select at all now? What does this buy us? Preference is generally not to use select.
I want to exclude the
CRC_T10DIF= m andSCSI_DEBUG= y combination because it causes the build to fail. I will leave out the select statement and will change "depends on SCSI" into the following:depends on SCSI && (m ||
CRC_T10DIF= y)Quoted 6 lines
Quoted 6 lines
drivers/scsi/scsi_debug-dif.h new file +3
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SCSI_DEBUG_DIF_H +#define _SCSI_DEBUG_DIF_HQuoted 8 lines
drivers/scsi/scsi_debug-dif.h line 9
Quoted 6 lines
drivers/scsi/scsi_debug-dif.h new file +6
-0+ +#include <linux/kconfig.h> +#include <linux/types.h> +#include <linux/spinlock_types.h> + +struct scsi_cmnd ;Do you really need to have a prototype for this? I'm a bit in shock seeing this in a scsi low-level driver.
I will leave the above out and add "#include <
scsi/scsi_cmnd.h>" instead.Quoted 1 line
dix_writesis defined inmain.c, so surely this extern needs to be inscsi_debug_dif.cor a common headerThe
scsi_debug-dif.hheader file is included from two .c files. Without this header file, the compiler wouldn't be able to check the consistency of the declarations inscsi_debug-dif.hwith the definitions in the twoscsi_debug.c files.Quoted 1 line
For me, I would actually just declare this in
scsi_debug_dif.cand havescsi_debug_dif_get_dix_writes()or similar to return this value. This function would be stubbed forCONFIG_CRC_T10DIF=nMy goal is to minimize changes while splitting the
scsi_debugsource code. Hence the "extern" declaration.Quoted 10 lines
drivers/scsi/scsi_debug-dif.h line 17
Quoted 8 lines
drivers/scsi/scsi_debug-dif.h new file +8
-0+extern int dix_reads; +extern int dif_errors; +extern struct xarray *const per_store_ap; +extern int sdebug_dif; +extern int sdebug_dix; +extern unsigned int sdebug_guard; +extern int sdebug_sector_size; +extern unsigned int sdebug_store_sectors;I doubt why all these are here
All the variables declared above are used in both
scsi_debug_dif.candscsi_debug_main.c.Quoted 5 lines
Quoted 3 lines
drivers/scsi/scsi_debug-dif.h new file +1
-0+int dif_verify(struct t10_pi_tuple *sdt, const void *data, sector_tsector,
+ u32ei_lba);Is this actually used in
main.c?It is not. I will remove it.
Quoted 1 line
I do also notice that we have chunks of code in
main.cthat does PI checking, like inresp_write_scat()- surely dif stuff should be indif.cnowI'm concerned that moving that code would make
resp_write_scat()much less readable. Please note that the code inresp_write_scat()that does PI checking is guarded by an 'if (have_dif_prot)' check and thathave_dif_prot= false ifCONFIG_CRC_T10DIF=n.Quoted 7 lines
drivers/scsi/scsi_debug_dif.c line 2
Quoted 5 lines
drivers/scsi/scsi_debug_dif.c new file +2
-0@@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include "scsi_debug-dif.h" I always find it is strange to include driver proprietary header files before common header files - I guess that is why the
scsi_cmndprototype is declared, aboveIncluding driver-private header files first is required by some coding style guides because it causes the build to fail if the driver-private header file does not include all include files it should include. See also
https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes
(I am aware that this style guide does not apply to Linux kernel code).Thanks,
Bart.
Quoted 43 lines · John Garry
drivers/scsi/scsi_debug.c +1
-0@@ -3471,6 +3471,7 @@ static bool comp_write_worker(struct sdeb_store_info *sip, u64 lba, u32 num, return res; } +#if (IS_ENABLED (CONFIG_CRC_T10DIF )) static __be16 dif_compute_csum(const void *buf, int len) {
__be16csum;drivers/scsi/scsi_debug.c +7
-0@@ -3509,6 +3510,13 @@ static int dif_verify(struct t10_pi_tuple *sdt, const void *data, } return 0; } +#else +static int dif_verify (struct t10_pi_tuple *sdt,const void *data, + sector_t sector, u32 ei_lba) +{ + return -EOPNOTSUPP; +} +#endif static void dif_copy_prot(struct scsi_cmnd *scp, sector_t sector,unsigned int sectors, bool read)
drivers/scsi/scsi_debug.c +5
-1@@ -7421,7 +7429,12 @@ static int __init scsi_debug_init(void) case T10_PI_TYPE1_PROTECTION: case T10_PI_TYPE2_PROTECTION: case T10_PI_TYPE3_PROTECTION: + #if (IS_ENABLED(CONFIG_CRC_T10DIF)) have_dif_prot = true; + #else + pr_err("CRC_T10DIF not enabled\n"); + return -EINVAL; + #endif break; default: ----8<-----
Quoted 1 line
I know that
IS_ENABLED(CONFIG_XXX)) ain't too nice to use, but this is a lot less change and we also don't need multiple files for the driver. As below, it's not easy to separate the CRC_T10DIF-related stuff out.
The above suggestion violates the following rule from the Linux kernel coding style: "As a general rule, #ifdef use should be confined to header files whenever possible." See alsoDocumentation/process/4.Coding.rst.
The approach to use multiple files in order to avoid #ifdefs in .c files is strongly preferred in Linux kernel code.
Thanks,
Bart.
Quoted 25 lines · Bart Van Assche
Quoted 25 lines
drivers/scsi/scsi_debug.c +7
-0+#else +static int dif_verify (struct t10_pi_tuple *sdt,const void *data, + sector_t sector, u32 ei_lba) +{ + return -EOPNOTSUPP; +} +#endif static void
dif_copy_prot(struct scsi_cmnd *scp, sector_t sector, unsigned int sectors, bool read)(quoted diff) +0
-0@@ -7421,7 +7429,12 @@ static int __init scsi_debug_init(void)case
T10_PI_TYPE1_PROTECTION:
caseT10_PI_TYPE2_PROTECTION:
caseT10_PI_TYPE3_PROTECTION:
+ #if (IS_ENABLED(CONFIG_CRC_T10DIF))
have_dif_prot= true;
+ #else
+pr_err("CRC_T10DIF not enabled\n");
+ return-EINVAL;
+ #endif
break;default:
----8<-----
Quoted 8 lines
Quoted 1 line
I know that
IS_ENABLED(CONFIG_XXX)) ain't too nice to use, but this is a lot less change and we also don't need multiple files for the driver. As below, it's not easy to separate the CRC_T10DIF-related stuff out.The above suggestion violates the following rule from the Linux kernel coding style: "As a general rule, #ifdef use should be confined to header files whenever possible." See also
Documentation/process/4.Coding.rst.The approach to use multiple files in order to avoid #ifdefs in .c files is strongly preferred in Linux kernel code.
Then what about this change in this patch:
Quoted 4 lines
+#ifdef
CONFIG_CRC_T10DIFMODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)"); +#endif
The idea of putting #ifdef in headers is that we can stub APIs. But that does not work for CRC_T10DIF, as the APIs don't return error codes - that's why there are no stubs today.
And, as noted, this is a general rule.
BTW, I don't think that modparams should be compiled out like this. Better would be to leave as is, and error when the user sets them.
scsi_debug is complex, to put it gently. I don't see any value in splitting it into further files, spreading the complexity. More especially when there seems to be little gain. scsi_debug requires CRC_T10DIF, so let it have it.
Thanks,
John
John,
Quoted 4 lines
scsi_debugis complex, to put it gently. I don't see any value in splitting it into further files, spreading the complexity. More especially when there seems to be little gain.scsi_debugrequiresCRC_T10DIF, so let it have it.
Yeah, I'm not sure this is worth the effort. It's a debug driver.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 10 lines · John Garry
Quoted 2 lines · Bart Van Assche
The approach to use multiple files in order to avoid #ifdefs in .c files is strongly preferred in Linux kernel code.
Then what about this change in this patch:
Quoted 4 lines
+#ifdef
CONFIG_CRC_T10DIFMODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)"); +#endif
This ifdef has been removed in v3.
Quoted 1 line
BTW, I don't think that modparams should be compiled out like this. Better would be to leave as is, and error when the user sets them.
Hmm ... aren't unrecognized kernel module parameters ignored silently? See also unknown_module_param_cb() in the kernel code.
Quoted 1 line
scsi_debugis complex, to put it gently. I don't see any value in splitting it into further files, spreading the complexity. More especially when there seems to be little gain.scsi_debugrequiresCRC_T10DIF, so let it have it.
We are using the scsi_debug driver in Android for kernel regression testing but there are no plans to support T10-PI in Android. Any proposals for alternative solutions for removing the dependency of the scsi_debug driver on the CRC_T10DIF code are welcome.
Thanks,
Bart.