-1

Given a SCSI device as input, I am trying to implement a kernel module that can :

Get the list of SCSI commands sent to that particular device and count the number of times that command was given.

How do I proceed to implement this?

I am a beginner at programming kernel modules, In fact I have only written a "Hello, World" program till now.

  • 2
    You should probably start reading a (few) tutorial(s) and come back later with more specific questions. :) – Tom K. Aug 11 '16 at 12:07
  • I've been reading through the popular [LKMP Guide](http://www.tldp.org/LDP/lkmpg/2.6/html/index.html). But, I don't seem to get my head around on how to implement this. – aerocarbine Aug 11 '16 at 12:13

1 Answers1

2

I believe there is already debugging and logging support on device driver side.

As a startpoint you should investigate the driver in the linux kernel which starts here:

https://github.com/torvalds/linux/blob/master/drivers/scsi/scsi_module.c

And for the debugging you find this one:

https://github.com/torvalds/linux/blob/master/drivers/scsi/scsi_logging.c

And it is always a good idea to read the manual first! Give it a chance here:

https://www.kernel.org/doc/Documentation/scsi/

If you can't get logging activated, you should come back and ask a more specific question. But I believe you have no need to write your own logger at all.

From http://www.theunixway.com/2013/10/ol56-enable-additional-scsi-logging-or.html

Enabling scsi logging on kernel:

sysctl -q -w dev.scsi.logging_level=<N>

or

echo <N> > /proc/dev/scsi/logging_level

N is a bit field which contains different categories of logging information. Please refer to the documentation of the actual kernel driver version you use.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Klaus
  • 24,205
  • 7
  • 58
  • 113
  • This actually would be better suited as a comment. It is more of a hint, than something that solves the problem. Also: links may die out, and answers should be usable for users in the upcoming future. – Tom K. Aug 11 '16 at 12:30
  • The relative file name will stay for a while, also if the repo moves. So I am in hope that in the future people will find the related stuff. And answering that logging is already supported seems to be an answer to me if that is a question for a xy-problem. I can't see any use case for writing new logging stuff. So I disagree that this is not an answer, because it points to a existing solution to the underlaying problem. – Klaus Aug 11 '16 at 12:34