Linux Kernel Source의 Block Device Driver에 사용되는 구조체

청랑의 이미지

Linux File System을 공부하고 있습니다.
하드 디스크에 파일이 어떻게 쓰여지는지 Linux Kernel Source Code를 뒤지다가 다음의 구조체를 발견했습니다.

struct request {
struct list_head queue;
int elevator_sequence;

volatile int rq_status; /* should split this into a few status bits */
#define RQ_INACTIVE (-1)
#define RQ_ACTIVE 1
#define RQ_SCSI_BUSY 0xffff
#define RQ_SCSI_DONE 0xfffe
#define RQ_SCSI_DISCONNECTING 0xffe0

kdev_t rq_dev;
int cmd; /* READ or WRITE */
int errors;
unsigned long start_time;
unsigned long sector;
unsigned long nr_sectors;
unsigned long hard_sector, hard_nr_sectors;
unsigned int nr_segments;
unsigned int nr_hw_segments;
unsigned long current_nr_sectors, hard_cur_sectors;

void * special;
char * buffer;
struct completion * waiting;
struct buffer_head * bh;
struct buffer_head * bhtail;
request_queue_t *q;
};

하드 디스크에 데이터를 읽거나 쓸 경우 경우 접근 속도 때문에 같은 방향성을 가진 요청을 몰아서 처리하는 엘리베이터 알고리즘을 사용합니다.
이 엘리베이터 알고리즘에 따라 하드 디스크 접근 요청들은 이중 연결 큐로 저장이 되고 위의 구조체가 큐에 저장되는 request입니다.
그런데 위에 밑줄 그어진 sector라는 이름이 붙은 구조체 멤버가 어떤 것인지 알수가 없네요..
소스 코드에는 주석 없이 달랑 저렇게 있고 관련 문서도 없구요..
제 생각에는 하드 디스크에 접근할때의 sector number인 거 같은데.. 확실치가 않네요..
혹 아시는 분 있으시면 답변 바랍니다.

그럼 고수님들의 고견 부탁 드립니다.

청랑의 이미지

다른 경로를 통해 답을 찾았습니다. 그래서 질문을 지울까 했는데 그냥 답까지 올려서 공유하는게 좋을거 같네요..

-----------------------------------------------------------------------
sector 번호에는 논리번호와 물리번호가 있읍니다. 물리번호는 track 마다 sector를 1 부터 번호를 붙인것
이고, 논리번호는 디스크의 첫 sector 를 0 으로 시작해서 디스크 끝까지 번호를 붙여나가는 것입니다. 리
눅스는 디스크 관리를 위해서 주로 논리번호를 사용하지만, 실제로 디스크 I/O 를 위해서는 물리번호로
바꾸어 줍니다.

sector 필드는 request 해야할 (buffer block 에 매핑된) disk block 내의 첫번째 sector 의 논리번호입니
다. request 의 최소 단위는 요즘 리눅스의 disk block 크기인 4KB 입니다.

current_nr_sectors 는 I/O 가 이루어져야 할 sector 수로서, 디스크에 저장할 buffer block 이 4 KB 이
면, 필드값은 sector 수인 8 이 됩니다. (make_request 함수 참고)
nr_sectors 는 I/O 를 위해 남은 sector 의 수입니다. 그래서 1개의 sector가 작업이 끝나면 sector 값
은 다음 sector 를 가리키기 위해 1 증가하고, nr_sectors 값은 1 감소합니다.

hard_sector, hard_nr_sectors, hard_cur_sectors 등은 여러개의 하드 디스크를 1 개의 디스크처럼 논리
적으로 연결해서 사용하는 LVM 이나 mirror 디스크를 만드는 RAID 등을 위해 만들어진 필드들입니다.
평소에는 sector, nr_sectors, current_nr_sectors 와 같은 값을 가지지만, 디스크 2개가 연결되면
sector 필드는 첫번째 디스크에서 두번째 디스크로 넘어갈때 연결되어서 번호가 증가하지만
hard_sector 는 다시 0 부터 시작합니다. 즉 하드웨어에 그만큼 종속적인 필드들입니다

리눅스 커널 분석 2.4 저자 박장수님

Evaluate yourself with your value, not your effort!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.