아무것도 몰라요

실험실 (커널 오류)

[NOVA] system call argument 추가 오류(1)

telomere37 2021. 7. 17. 22:40

이제 실제 어디에 어떤 구현을 할 것인지 대충 정해야 될 때가 왔다. 하지만 그 전에 file operation을 설정해줘야되는데, 이를 시험하기 위해서 system call을 약간 수정하였다. 하지만 약간 수정한 system call에서 오류가 바로 발생하였고, system call에서 오류가 발생한 것을 고치기 위해서 끊임없이 build를 하고 있다. 우선 바꾼 system call을 살펴보면 다음과 같다.

#include<linux/kernel.h>
#include<linux/syscalls.h>
#include<linux/file.h>
#include<linux/fs.h>

SYSCALL_DEFINE1(dedup, unsigned int, fd){
  printk("0\n");
  struct fd f = fdget_pos(fd);
  printk("1\n");
  struct file *file = f.file;
  printk("2\n");
  file ->f_op->dedup();
  printk("3\n");
  return 0;
}

printk는 디버깅을 위한 것이라 무시해도 된다. 우선 하나의 fd를 받아와서 이에 대한 file구조체를 받아오고, 이 구조체에 접근해서 file operation의 dedup을 호출하는 방식을 진행하였다. 우선 해당 system call이 호출이 되도록 system call header도 수정을 하여 정상적으로 작동하는 것을 확인하였다. 하지만 여기서 fdget_pos등의 함수를 사용하는 순간 "Killed"가 된다. 

 

1차 시도

#include<linux/kernel.h>
#include<linux/syscalls.h>
#include<linux/file.h>
#include<linux/fs.h>


int ksys_dedup(unsigned int fd){
  printk("1\n");
  struct fd f = fdget_pos(fd);
  return 0;
}


SYSCALL_DEFINE1(dedup, unsigned int, fd){
  printk("0\n");
  return ksys_dedup(fd);
}

우선 ksys_write처럼 다른 함수를 호출하도록 하였다. fdget_pos에서 오류가 검출되는지 확인해보겠다. 

----- build 중.... ------

결과: 통과

잘...나오네?

2차 시도

#include<linux/kernel.h>
#include<linux/syscalls.h>
#include<linux/file.h>
#include<linux/fs.h>


int ksys_dedup(unsigned int fd){
  printk("1\n");
  struct fd f = fdget_pos(fd);
  printk("2\n");
  struct file *file = f.file;
  printk("3\n");
  file->f_op->dedup();
  return 0;
}


SYSCALL_DEFINE1(dedup, unsigned int, fd){
  printk("0\n");
  return ksys_dedup(fd);
}

잘 되는 것 같아서 일단 SYSCALL에서 호출한 것이 문제였던 것 같아 그냥 그대로 ksys_dedup에 기존 호출들을 다 때려 넣었다. 실험할 때는 nova.ko를 mount한 뒤에 실행하였다. 

----- build 중 ------

결과: 불통

3까지 출력되는 것으로 보아, f_op -> deup()에서 문제가 발생한 것 같다. 왜일까? VFS에 File operation에 먼저 추가를 해줬긴한데... 그 operation에 대응하는 무언가를 먼저 설정해줬어야 되나..? 그리고 거기서 이제 f_op의 dedup을 호출 하도록? VFS를 제대로 배운적이 없어서 더 혼란스럽다. 

 

3차 시도

Write system call에 f_op->dedup()을 추가했다가 서버가 터져버렸다 ㅎ