Re: [PATCH 1/8] sg: types and naming cleanup

2018-10-19 Thread Johannes Thumshirn
On 19/10/18 08:24, Douglas Gilbert wrote:
> Remove typedefs and use better type names like bool and u8 where
> appropriate. Rename some variables and functions for clarity.
> Adjust formatting (e.g. function definitions) to be more
> consistent across the driver.

Thanks a lot Doug, this is highly appreciated.
I have one minor Nit if you need to resend the series, please remove the
casts form void* (mostly filp->private_data).

Otherwise:
Reviewed-by: Johannes Thumshirn 

-- 
Johannes ThumshirnSUSE Labs
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850


[PATCH 1/8] sg: types and naming cleanup

2018-10-19 Thread Douglas Gilbert
Remove typedefs and use better type names like bool and u8 where
appropriate. Rename some variables and functions for clarity.
Adjust formatting (e.g. function definitions) to be more
consistent across the driver.

Signed-off-by: Douglas Gilbert 
---

The intention is to move to sg_version_num 40001 when a second
patchset implementing SG_IOSUBMIT and friends is applied. In
the meantime, move from the latest version number in the kernel
(30536) to 30901 to indicate a significant change but not yet
implementing the sg v4 interface.

 drivers/scsi/sg.c | 827 ++
 1 file changed, 467 insertions(+), 360 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index c6ad00703c5b..7e723f37a269 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -7,7 +7,7 @@
  * Original driver (sg.c):
  *Copyright (C) 1992 Lawrence Foard
  * Version 2 and 3 extensions to driver:
- *Copyright (C) 1998 - 2014 Douglas Gilbert
+ *Copyright (C) 1998 - 2018 Douglas Gilbert
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,16 +16,9 @@
  *
  */
 
-static int sg_version_num = 30536; /* 2 digits for each component */
-#define SG_VERSION_STR "3.5.36"
+static int sg_version_num = 30901; /* 2 digits for each component */
+#define SG_VERSION_STR "3.9.01"
 
-/*
- *  D. P. Gilbert (dgilb...@interlog.com), notes:
- *  - scsi logging is available via SCSI_LOG_TIMEOUT macros. First
- *the kernel/module needs to be built with CONFIG_SCSI_LOGGING
- *(otherwise the macros compile to empty statements).
- *
- */
 #include 
 
 #include 
@@ -52,6 +45,8 @@ static int sg_version_num = 30536;/* 2 digits for each 
component */
 #include 
 #include 
 #include  /* for sg_check_file_access() */
+#include 
+#include 
 
 #include "scsi.h"
 #include 
@@ -64,7 +59,7 @@ static int sg_version_num = 30536;/* 2 digits for each 
component */
 
 #ifdef CONFIG_SCSI_PROC_FS
 #include 
-static char *sg_version_date = "20140603";
+static char *sg_version_date = "20181018";
 
 static int sg_proc_init(void);
 #endif
@@ -73,7 +68,8 @@ static int sg_proc_init(void);
 
 #define SG_MAX_DEVS 32768
 
-/* SG_MAX_CDB_SIZE should be 260 (spc4r37 section 3.1.30) however the type
+/*
+ * SG_MAX_CDB_SIZE should be 260 (spc4r37 section 3.1.30) however the type
  * of sg_io_hdr::cmd_len can only represent 255. All SCSI commands greater
  * than 16 bytes are "variable length" whose length is a multiple of 4
  */
@@ -100,44 +96,54 @@ static int sg_add_device(struct device *, struct 
class_interface *);
 static void sg_remove_device(struct device *, struct class_interface *);
 
 static DEFINE_IDR(sg_index_idr);
-static DEFINE_RWLOCK(sg_index_lock);   /* Also used to lock
-  file descriptor list 
for device */
+static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock fd list for device */
 
 static struct class_interface sg_interface = {
.add_dev= sg_add_device,
.remove_dev = sg_remove_device,
 };
 
-typedef struct sg_scatter_hold { /* holding area for scsi scatter gather info 
*/
-   unsigned short k_use_sg; /* Count of kernel scatter-gather pieces */
-   unsigned sglist_len; /* size of malloc'd scatter-gather list ++ */
-   unsigned bufflen;   /* Size of (aggregate) data buffer */
-   struct page **pages;
-   int page_order;
-   char dio_in_use;/* 0->indirect IO (or mmap), 1->dio */
-   unsigned char cmd_opcode; /* first byte of command */
-} Sg_scatter_hold;
+struct sg_v4_hold {/* parts of sg_io_v4 object needed in async usage */
+   __user u8 *usr_ptr; /* derived from sg_io_v4::usr_ptr */
+   __user u8 *sbp; /* derived from sg_io_v4::response */
+   u16 cmd_len;/* truncated of sg_io_v4::request_len */
+   u16 max_sb_len; /* truncated of sg_io_v4::max_response_len */
+   u32 flags;  /* copy of sg_io_v4::flags */
+};
+
+struct sg_scatter_hold { /* holding area for scsi scatter gather info */
+   struct page **pages;/* num_sgat element array of struct page* */
+   int page_order; /* byte_len = (page_size * (2**page_order)) */
+   int dlen;   /* Byte length of data buffer */
+   unsigned short num_sgat;/* actual number of scatter-gather segments */
+   bool dio_in_use;/* false->indirect IO (or mmap), true->dio */
+   u8 cmd_opcode;  /* first byte of command */
+};
 
 struct sg_device;  /* forward declarations */
 struct sg_fd;
 
-typedef struct sg_request {/* SG_MAX_QUEUE requests outstanding per file */
+struct sg_request {/* SG_MAX_QUEUE requests outstanding per file */
struct list_head entry; /* list entry */
struct sg_fd *parentfp; /* NULL -> not in use */
-   Sg_scatter_hold