반응형

'The Linux SCSI programming HOWTO' 페이지 (http://www.tldp.org/HOWTO/archived/SCSI-Programming-HOWTO) 를 스터디 후 정리한 내용입니다.



리눅스 generic SCSI 인터페이스 프로그래밍과 관련된 문서


1. What's New?



2. Introduction


(1) 포함내용

 - Kernel 전제조건

 - 디바이스 매핑

 - 기본 동작


(2) 필요 배경 지식

 - SCSI 커맨드 셋



3. What is the generic SCSI interface?


SCSI 하드웨어를 사용할 수 있도록 지원.



4. What are the requirements to use it?


4.1. 커널 설정


커널 빌드 시 다음의 내용을 enable 시켜주어야 함.


 ...

*

* SCSI support

*

SCSI support? (CONFIG_SCSI) [n] y

*

* SCSI support type (disk, tape, CDrom)

*

 ...

Scsi generic support (CONFIG_CHR_DEV_SG) [n] y

*

* SCSI low-level drivers

*

 ...



4.2. 디바이스 파일


SCSI 디바이스의 블록 디바이스 경로는 '/dev/sgX' 로 표기됨.



4.3. 디바이스 매핑 (이해 X)


For example, assuming you had three SCSI devices hooked up with ids 1, 3, and 5 on the first SCSI bus (each having one LUN), then the following mapping would be in effect:


/dev/sga -> SCSI id 1

/dev/sgb -> SCSI id 3

/dev/sgc -> SCSI id 5


If you now add a new device with id 4, then the mapping (after the next rescan) will be:


/dev/sga -> SCSI id 1

/dev/sgb -> SCSI id 3

/dev/sgc -> SCSI id 4

/dev/sgd -> SCSI id 5


Notice the change for id 5 -- the corresponding device is no longer mapped to /dev/sgc but is now under /dev/sgd.



4.3.1. SCSI 디바이스의 동적 추가/제거


proc을 사용하여 추가 제거가 가능함.


제거 : echo "scsi remove-single-device a b c d" > /proc/scsi/scsi


 추가 : echo "scsi add-single-device a b c d" > /proc/scsi/scsi


 a == hostadapter id (first one being 0)

 b == SCSI channel on hostadapter (first one being 0)

 c == ID

 d == LUN (first one being 0)



예시 - sgc와 sgd의 SWAP 시


$ echo "scsi remove-single-device 0 0 4 0" > /proc/scsi/scsi

 $ echo "scsi remove-single-device 0 0 5 0" > /proc/scsi/scsi

 $ echo "scsi add-single-device 0 0 5 0" > /proc/scsi/scsi

 $ echo "scsi add-single-device 0 0 4 0" > /proc/scsi/scsi



5. 프로그래머 가이드


SCSI 인터페이스를 애플리케이션에서 사용하는 방법에 대한 설명.



(1) 커널 1.3.98 부터 관련 헤더파일 (sg.h, scsi.h)이 '/usr/src/linux/include/scsi'로 옮겨졌고, '/usr/include/scsi' 에 링크되어 있음. (1.3.98 이전에는 '/usr/src/linux/drivers/scsi' 에 위치)



(2) Generic SCSI 인터페이스는 커널 1.1.68 부터 적용되어 있음. 하지만 1.1.77과 1.3.52에서는 문제가 있으므로, 1.1.77은 1.1.89로, 1.3.52는 1.3.56으로 버전업 하여 사용 필요.



6. 디바이스 프로그래밍 개요


include/scsi/sg.h 헤더파일 (커널 1.3.98 기준)


struct sg_header

 {

  int pack_len;

                   /* length of incoming packet (including header) */

  int reply_len;   /* maximum length of expected reply */

  int pack_id;     /* id number of packet */

  int result;      /* 0==ok, otherwise refer to errno codes */

  unsigned int twelve_byte:1;

               /* Force 12 byte command length for group 6 & 7 commands  */

  unsigned int other_flags:31;                  /* for future use */

  unsigned char sense_buffer[16]; /* used only by reads */

  /* command follows then data for command */

 }; 


** generic driver와 데이터 교환 방법 **


(1) generic device를 open 하기 위한 커맨드 send


(2) 다음 블럭에 write() 수행

       - struct sg_header

       - SCSI command

       - data to be sent with the command


 (3) 다음 블럭에 read() 수행

        - struct sg_header

        - data coming from the device

반응형
Posted by 해리팍
BLOG main image

Chanhyun Park (해리팍)
Software Engineer @ SK hynix

Contact Info.
parkch0708@hanmail.net
chanhyun0708@gmail.com
chanhyun.park@sk.com

카테고리

All (1501)
Profile (2)
Park's Life (599)
Computer System (165)
Computer Programming (39)
Computer Study (54)
Computer Etc. (189)
Scuba Diving (137)
Golf (8)
Traveling (245)
생활 정보 (12)
Pokemon GO (50)