Skip to contentSkip to conversation

cifs: small clean up series

PATCH In review Andy Shevchenko 3 participants 8 messages Aug 27, 2014 – Dec 8, 2014 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover cifs: small clean up series

This is small clean up series against CIFS kernel module.

Changes since v3:
- rebase on top of recent linux-next

Changes since v2:
- patch 1 got ACK and Reviwed-by tags
- patch 2 incorporates new piece of code similar that it used to have already, thus tags were dropped for this round
- new patch 3

Andy Shevchenko (3):
cifs: call strtobool instead of custom implementation
cifs: convert to print_hex_dump() instead of custom implementation
cifs: convert printk(LEVEL...) to pr_<level>

 fs/cifs/cifs_debug.c | 77 ++++++++++++++++++++++------------------------------
 fs/cifs/cifs_debug.h |  7 ++---
 fs/cifs/connect.c    | 51 ++++++++++++----------------------
 fs/cifs/misc.c       | 32 ++--------------------
 fs/cifs/transport.c  |  4 +--
 5 files changed, 58 insertions(+), 113 deletions(-)
Signature · 1 line
2.1.0

A message that is not in the archive (sent off-list or not yet received): 1409147384-20389-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]

#2 lore raw

PATCH v4 1/3 cifs: call strtobool instead of custom implementation

Meanwhile it cleans up the code, the behaviour is slightly changed. In case of providing non-boolean value it will fails with corresponding error. In the original code the attempt of an update was just ignored in such case.

---
 fs/cifs/cifs_debug.c | 51 +++++++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 22 deletions(-)
fs/cifs/cifs_debug.c +29 -22
index 44ec726..7c50bfa 100644
@@ -274,6 +274,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
 		const char __user *buffer, size_t count, loff_t *ppos)
 {
 	char c;
+	bool bv;
 	int rc;
 	struct list_head *tmp1, *tmp2, *tmp3;
 	struct TCP_Server_Info *server;
@@ -284,7 +285,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
 	if (rc)
 		return rc;
 
-	if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
+	if (strtobool(&c, &bv) == 0) {
 #ifdef CONFIG_CIFS_STATS2
 		atomic_set(&totBufAllocCount, 0);
 		atomic_set(&totSmBufAllocCount, 0);
@@ -451,15 +452,14 @@ static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
 		size_t count, loff_t *ppos)
 {
 	char c;
+	bool bv;
 	int rc;
 
 	rc = get_user(c, buffer);
 	if (rc)
 		return rc;
-	if (c == '0' || c == 'n' || c == 'N')
-		cifsFYI = 0;
-	else if (c == '1' || c == 'y' || c == 'Y')
-		cifsFYI = 1;
+	if (strtobool(&c, &bv) == 0)
+		cifsFYI = bv;
 	else if ((c > '1') && (c <= '9'))
 		cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
 
@@ -490,15 +490,18 @@ static ssize_t cifs_linux_ext_proc_write(struct file *file,
 		const char __user *buffer, size_t count, loff_t *ppos)
 {
 	char c;
+	bool bv;
 	int rc;
 
 	rc = get_user(c, buffer);
 	if (rc)
 		return rc;
-	if (c == '0' || c == 'n' || c == 'N')
-		linuxExtEnabled = 0;
-	else if (c == '1' || c == 'y' || c == 'Y')
-		linuxExtEnabled = 1;
+
+	rc = strtobool(&c, &bv);
+	if (rc)
+		return rc;
+
+	linuxExtEnabled = bv;
 
 	return count;
 }
@@ -527,15 +530,18 @@ static ssize_t cifs_lookup_cache_proc_write(struct file *file,
 		const char __user *buffer, size_t count, loff_t *ppos)
 {
 	char c;
+	bool bv;
 	int rc;
 
 	rc = get_user(c, buffer);
 	if (rc)
 		return rc;
-	if (c == '0' || c == 'n' || c == 'N')
-		lookupCacheEnabled = 0;
-	else if (c == '1' || c == 'y' || c == 'Y')
-		lookupCacheEnabled = 1;
+
+	rc = strtobool(&c, &bv);
+	if (rc)
+		return rc;
+
+	lookupCacheEnabled = bv;
 
 	return count;
 }
@@ -564,15 +570,18 @@ static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
 		size_t count, loff_t *ppos)
 {
 	char c;
+	bool bv;
 	int rc;
 
 	rc = get_user(c, buffer);
 	if (rc)
 		return rc;
-	if (c == '0' || c == 'n' || c == 'N')
-		traceSMB = 0;
-	else if (c == '1' || c == 'y' || c == 'Y')
-		traceSMB = 1;
+
+	rc = strtobool(&c, &bv);
+	if (rc)
+		return rc;
+
+	traceSMB = bv;
 
 	return count;
 }
@@ -630,6 +639,7 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
 	unsigned int flags;
 	char flags_string[12];
 	char c;
+	bool bv;
 
 	if ((count < 1) || (count > 11))
 		return -EINVAL;
@@ -642,11 +652,8 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
 	if (count < 3) {
 		/* single char or single char followed by null */
 		c = flags_string[0];
-		if (c == '0' || c == 'n' || c == 'N') {
-			global_secflags = CIFSSEC_DEF; /* default */
-			return count;
-		} else if (c == '1' || c == 'y' || c == 'Y') {
-			global_secflags = CIFSSEC_MAX;
+		if (strtobool(&c, &bv) == 0) {
+			global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
 			return count;
 		} else if (!isdigit(c)) {
 			cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
Signature · 1 line
2.1.0
#3 lore raw

PATCH v4 2/3 cifs: convert to print_hex_dump() instead of custom implementation

In reply to a message not in the archive

This patch converts custom dumper to use native print_hex_dump() instead. The cifs_dump_mem() will have an offsets per each line which differs it from the original code.

In the dump_smb() we may use native print_hex_dump() as well. It will show slightly different output in ASCII part when character is unprintable, otherwise it keeps same structure.

---
 fs/cifs/cifs_debug.c | 21 ++-------------------
 fs/cifs/misc.c       | 32 ++------------------------------
 2 files changed, 4 insertions(+), 49 deletions(-)
fs/cifs/cifs_debug.c +2 -19
index 7c50bfa..14e082f 100644
@@ -34,27 +34,10 @@
 void
 cifs_dump_mem(char *label, void *data, int length)
 {
-	int i, j;
-	int *intptr = data;
-	char *charptr = data;
-	char buf[10], line[80];
-
 	printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
 		label, length, data);
-	for (i = 0; i < length; i += 16) {
-		line[0] = 0;
-		for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
-			sprintf(buf, " %08x", intptr[i / 4 + j]);
-			strcat(line, buf);
-		}
-		buf[0] = ' ';
-		buf[2] = 0;
-		for (j = 0; (j < 16) && (i + j < length); j++) {
-			buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
-			strcat(line, buf);
-		}
-		printk(KERN_DEBUG "%s\n", line);
-	}
+	print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
+		       data, length, true);
 }
 
 #ifdef CONFIG_CIFS_DEBUG
fs/cifs/misc.c +2 -30
index b7415d5..3379463 100644
@@ -513,39 +513,11 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
 void
 dump_smb(void *buf, int smb_buf_length)
 {
-	int i, j;
-	char debug_line[17];
-	unsigned char *buffer = buf;
-
 	if (traceSMB == 0)
 		return;
 
-	for (i = 0, j = 0; i < smb_buf_length; i++, j++) {
-		if (i % 8 == 0) {
-			/* have reached the beginning of line */
-			printk(KERN_DEBUG "| ");
-			j = 0;
-		}
-		printk("%0#4x ", buffer[i]);
-		debug_line[2 * j] = ' ';
-		if (isprint(buffer[i]))
-			debug_line[1 + (2 * j)] = buffer[i];
-		else
-			debug_line[1 + (2 * j)] = '_';
-
-		if (i % 8 == 7) {
-			/* reached end of line, time to print ascii */
-			debug_line[16] = 0;
-			printk(" | %s\n", debug_line);
-		}
-	}
-	for (; j < 8; j++) {
-		printk("     ");
-		debug_line[2 * j] = ' ';
-		debug_line[1 + (2 * j)] = ' ';
-	}
-	printk(" | %s\n", debug_line);
-	return;
+	print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, 8, 2, buf,
+		       smb_buf_length, true);
 }
 
 void
Signature · 1 line
2.1.0
#4 lore raw

Re: [PATCH v4 2/3] cifs: convert to print_hex_dump() instead of custom implementation

Do you have a sample for what the output change looks like?

Quoted 97 lines · Andy Shevchenko

This patch converts custom dumper to use native print_hex_dump() instead. The cifs_dump_mem() will have an offsets per each line which differs it from the original code.

In the dump_smb() we may use native print_hex_dump() as well. It will show slightly different output in ASCII part when character is unprintable, otherwise it keeps same structure.

---
 fs/cifs/cifs_debug.c | 21 ++-------------------
 fs/cifs/misc.c       | 32 ++------------------------------
 2 files changed, 4 insertions(+), 49 deletions(-)
fs/cifs/cifs_debug.c +2 -19
index 7c50bfa..14e082f 100644
@@ -34,27 +34,10 @@
 void
 cifs_dump_mem(char *label, void *data, int length)
 {
-       int i, j;
-       int *intptr = data;
-       char *charptr = data;
-       char buf[10], line[80];
-
        printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
                label, length, data);
-       for (i = 0; i < length; i += 16) {
-               line[0] = 0;
-               for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
-                       sprintf(buf, " %08x", intptr[i / 4 + j]);
-                       strcat(line, buf);
-               }
-               buf[0] = ' ';
-               buf[2] = 0;
-               for (j = 0; (j < 16) && (i + j < length); j++) {
-                       buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
-                       strcat(line, buf);
-               }
-               printk(KERN_DEBUG "%s\n", line);
-       }
+       print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
+                      data, length, true);
 }
 
 #ifdef CONFIG_CIFS_DEBUG
fs/cifs/misc.c +2 -31
index b7415d5..3379463 100644
@@ -513,39 +513,11 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
 void
 dump_smb(void *buf, int smb_buf_length)
 {
-       int i, j;
-       char debug_line[17];
-       unsigned char *buffer = buf;
-
        if (traceSMB == 0)
                return;
 
-       for (i = 0, j = 0; i < smb_buf_length; i++, j++) {
-               if (i % 8 == 0) {
-                       /* have reached the beginning of line */
-                       printk(KERN_DEBUG "| ");
-                       j = 0;
-               }
-               printk("%0#4x ", buffer[i]);
-               debug_line[2 * j] = ' ';
-               if (isprint(buffer[i]))
-                       debug_line[1 + (2 * j)] = buffer[i];
-               else
-                       debug_line[1 + (2 * j)] = '_';
-
-               if (i % 8 == 7) {
-                       /* reached end of line, time to print ascii */
-                       debug_line[16] = 0;
-                       printk(" | %s\n", debug_line);
-               }
-       }
-       for (; j < 8; j++) {
-               printk("     ");
-               debug_line[2 * j] = ' ';
-               debug_line[1 + (2 * j)] = ' ';
-       }
-       printk(" | %s\n", debug_line);
-       return;
+       print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, 8, 2, buf,
+                      smb_buf_length, true);
 }
 
 void
--

2.1.0

Signature · 3 lines
Thanks,

Steve

A message that is not in the archive (sent off-list or not yet received): CAH2r5muAtFu9YT8etmTvoFs-SJpeANGLLUtdRQaoj3FN+yxozw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw

Re: [PATCH v4 2/3] cifs: convert to print_hex_dump() instead of custom implementation

Quoted 2 lines · Steve French

Do you have a sample for what the output change looks like?

Just for some random data (only dumps) on x86_64.

cifs_dump_mem():

[   13.842342] 00000000: a0000222 ffffffff a0000282 ffffffff  "...............
[   13.850140] 00000010: 00000001 00000000 a000028f ffffffff  ................
[   13.857930] 00000020: 00000009 00000000 a00002a2 ffffffff  ................
[   13.865726] 00000030: 00000021 00000000 00000000 00000000  !...............

dump_smb():

[   14.859103] 0222 a000 ffff ffff 0282 a000 ffff ffff  "...............
[   14.866313] 0001 0000 0000 0000 028f a000 ffff ffff  ................
[   14.873528] 0009 0000 0000 0000 02a2 a000 ffff ffff  ................
[   14.880736] 0021 0000 0000 0000 0000 0000 0000 0000  !...............
Quoted 102 lines
Quoted 97 lines · Andy Shevchenko

This patch converts custom dumper to use native print_hex_dump() instead. The cifs_dump_mem() will have an offsets per each line which differs it from the original code.

In the dump_smb() we may use native print_hex_dump() as well. It will show slightly different output in ASCII part when character is unprintable, otherwise it keeps same structure.

---
 fs/cifs/cifs_debug.c | 21 ++-------------------
 fs/cifs/misc.c       | 32 ++------------------------------
 2 files changed, 4 insertions(+), 49 deletions(-)
fs/cifs/cifs_debug.c +2 -19
index 7c50bfa..14e082f 100644
@@ -34,27 +34,10 @@
 void
 cifs_dump_mem(char *label, void *data, int length)
 {
-       int i, j;
-       int *intptr = data;
-       char *charptr = data;
-       char buf[10], line[80];
-
        printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
                label, length, data);
-       for (i = 0; i < length; i += 16) {
-               line[0] = 0;
-               for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
-                       sprintf(buf, " %08x", intptr[i / 4 + j]);
-                       strcat(line, buf);
-               }
-               buf[0] = ' ';
-               buf[2] = 0;
-               for (j = 0; (j < 16) && (i + j < length); j++) {
-                       buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
-                       strcat(line, buf);
-               }
-               printk(KERN_DEBUG "%s\n", line);
-       }
+       print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
+                      data, length, true);
 }
 
 #ifdef CONFIG_CIFS_DEBUG
fs/cifs/misc.c +2 -31
index b7415d5..3379463 100644
@@ -513,39 +513,11 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
 void
 dump_smb(void *buf, int smb_buf_length)
 {
-       int i, j;
-       char debug_line[17];
-       unsigned char *buffer = buf;
-
        if (traceSMB == 0)
                return;
 
-       for (i = 0, j = 0; i < smb_buf_length; i++, j++) {
-               if (i % 8 == 0) {
-                       /* have reached the beginning of line */
-                       printk(KERN_DEBUG "| ");
-                       j = 0;
-               }
-               printk("%0#4x ", buffer[i]);
-               debug_line[2 * j] = ' ';
-               if (isprint(buffer[i]))
-                       debug_line[1 + (2 * j)] = buffer[i];
-               else
-                       debug_line[1 + (2 * j)] = '_';
-
-               if (i % 8 == 7) {
-                       /* reached end of line, time to print ascii */
-                       debug_line[16] = 0;
-                       printk(" | %s\n", debug_line);
-               }
-       }
-       for (; j < 8; j++) {
-               printk("     ");
-               debug_line[2 * j] = ' ';
-               debug_line[1 + (2 * j)] = ' ';
-       }
-       printk(" | %s\n", debug_line);
-       return;
+       print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, 8, 2, buf,
+                      smb_buf_length, true);
 }
 
 void
--

2.1.0

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#7 lore raw

PATCH v4 3/3 cifs: convert printk(LEVEL...) to pr_<level>

In reply to a message not in the archive

The useful macros embed message level in the name. Thus, it cleans up the code a bit. In cases when it was plain printk() the conversion was done to info level.

---
 fs/cifs/cifs_debug.c |  5 ++---
 fs/cifs/cifs_debug.h |  7 +++----
 fs/cifs/connect.c    | 51 ++++++++++++++++++---------------------------------
 fs/cifs/transport.c  |  4 ++--
 4 files changed, 25 insertions(+), 42 deletions(-)
fs/cifs/cifs_debug.c +2 -3
index 14e082f..9c56ef7 100644
@@ -34,8 +34,7 @@
 void
 cifs_dump_mem(char *label, void *data, int length)
 {
-	printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
-		label, length, data);
+	pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
 	print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
 		       data, length, true);
 }
@@ -51,7 +50,7 @@ void cifs_vfs_err(const char *fmt, ...)
 	vaf.fmt = fmt;
 	vaf.va = &args;
 
-	printk(KERN_ERR "CIFS VFS: %pV", &vaf);
+	pr_err("CIFS VFS: %pV", &vaf);
 
 	va_end(args);
 }
fs/cifs/cifs_debug.h +3 -4
index c99b40f..f40fbac 100644
@@ -53,13 +53,12 @@ __printf(1, 2) void cifs_vfs_err(const char *fmt, ...);
 do {									\
 	if (type == FYI) {						\
 		if (cifsFYI & CIFS_INFO) {				\
-			printk(KERN_DEBUG "%s: " fmt,			\
-			       __FILE__, ##__VA_ARGS__);		\
+			pr_debug("%s: " fmt, __FILE__, ##__VA_ARGS__);	\
 		}							\
 	} else if (type == VFS) {					\
 		cifs_vfs_err(fmt, ##__VA_ARGS__);			\
 	} else if (type == NOISY && type != 0) {			\
-		printk(KERN_DEBUG fmt, ##__VA_ARGS__);			\
+		pr_debug(fmt, ##__VA_ARGS__);				\
 	}								\
 } while (0)
 
@@ -71,7 +70,7 @@ do {									\
 #define cifs_dbg(type, fmt, ...)					\
 do {									\
 	if (0)								\
-		printk(KERN_DEBUG fmt, ##__VA_ARGS__);			\
+		pr_debug(fmt, ##__VA_ARGS__);				\
 } while (0)
 #endif
 
fs/cifs/connect.c +18 -33

149 lines not on this page · raw message

fs/cifs/transport.c +2 -2
index 9d087f4..126f46b 100644
@@ -99,9 +99,9 @@ DeleteMidQEntry(struct mid_q_entry *midEntry)
 	   something is wrong, unless it is quite a slow link or server */
 	if ((now - midEntry->when_alloc) > HZ) {
 		if ((cifsFYI & CIFS_TIMER) && (midEntry->command != command)) {
-			printk(KERN_DEBUG " CIFS slow rsp: cmd %d mid %llu",
+			pr_debug(" CIFS slow rsp: cmd %d mid %llu",
 			       midEntry->command, midEntry->mid);
-			printk(" A: 0x%lx S: 0x%lx R: 0x%lx\n",
+			pr_info(" A: 0x%lx S: 0x%lx R: 0x%lx\n",
 			       now - midEntry->when_alloc,
 			       now - midEntry->when_sent,
 			       now - midEntry->when_received);
Signature · 1 line
2.1.0
#8 lore raw
In reply to a message not in the archive
Quoted 2 lines · Andy Shevchenko

This is small clean up series against CIFS kernel module.

Ping? Is there any comments?

Quoted 21 lines

Changes since v3:
- rebase on top of recent linux-next

Changes since v2:
- patch 1 got ACK and Reviwed-by tags
- patch 2 incorporates new piece of code similar that it used to have already, thus tags were dropped for this round
- new patch 3

Andy Shevchenko (3):
cifs: call strtobool instead of custom implementation
cifs: convert to print_hex_dump() instead of custom implementation
cifs: convert printk(LEVEL...) to pr_<level>

 fs/cifs/cifs_debug.c | 77 ++++++++++++++++++++++------------------------------
 fs/cifs/cifs_debug.h |  7 ++---
 fs/cifs/connect.c    | 51 ++++++++++++----------------------
 fs/cifs/misc.c       | 32 ++--------------------
 fs/cifs/transport.c  |  4 +--
 5 files changed, 58 insertions(+), 113 deletions(-)
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy

A message that is not in the archive (sent off-list or not yet received): 1413986632.2396.38.camel-VuQAYsv1563Yd54FQh9/[email protected]

#10 lore raw

series merged into cifs-2.6.git

Quoted 33 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

This is small clean up series against CIFS kernel module.

Ping? Is there any comments?

Quoted 14 lines

Changes since v3:
- rebase on top of recent linux-next

Changes since v2:
- patch 1 got ACK and Reviwed-by tags
- patch 2 incorporates new piece of code similar that it used to have already, thus tags were dropped for this round
- new patch 3

Andy Shevchenko (3):
cifs: call strtobool instead of custom implementation
cifs: convert to print_hex_dump() instead of custom implementation
cifs: convert printk(LEVEL...) to pr_<level>

Quoted 7 lines
 fs/cifs/cifs_debug.c | 77 ++++++++++++++++++++++------------------------------
 fs/cifs/cifs_debug.h |  7 ++---
 fs/cifs/connect.c    | 51 ++++++++++++----------------------
 fs/cifs/misc.c       | 32 ++--------------------
 fs/cifs/transport.c  |  4 +--
 5 files changed, 58 insertions(+), 113 deletions(-)

--
Andy Shevchenko <[email protected]> Intel Finland Oy

Signature · 3 lines
Thanks,

Steve