2008年12月22日 星期一

strace

trace system call and signals

linux multipath

load driver:
1. chkconfig boot.multipath on
2.chkconfig multipathd on
3. /etc/init.d/boot.multipath start
4. /etc/init.d/multipathd start

query multipath status:
multipath -l

stop multipath service:
1. /etc/init.d/boot.multipath stop
2. /etc/init.d/multipathd stop

/etc/scsi_id.config:
the info related to multipath

how to decide multipath:
the sds with the same uuid are combined into a dm
scsi_id -g -s /block/sda can get uuid

for red hat:
default multipath is not triggered
modify /etc/multipath.conf :
comment blacklist
remove dm:
multipath -F
multipath stop

2008年12月17日 星期三

iometer

In windows : GUI

In linux:  agent

Use windows iometer GUI to connect to linux iometer agent to get io information 

run iometer agent in linux:
./dynamo -i windows_gui_ip  -m linux_agent_ip

2008年12月15日 星期一

change log level & enable sysrq

echo 9 > /proc/sysrq-trigger

echo 1 >  /proc/sys/kernel/sysrq

alt + sysrq  +  p :  show cpu info

alt + sysrq  + t : show current task list

alt  + sysrq  + m : show memory info

redirect output from serial port

1. modify bios:
   (1)Change BIOS settings /Server/Serial Console Features/BIOS Redirection Port to
       [Serial port 1 or 2]
   (2)change direct to modem 

2.  modify /boot/grub/menu.lst for suse
     modify /boot/grub/grub.conf  for red hat
    console=ttyS0, 115200,vt100

3. modify /ect/inittab
    c0:2345:respawn:/sbin/agetty ttyS0 19200 vt100    

4. modify  /etc/securetty
    ttyS0

2008年12月9日 星期二

cpu info

cat /proc/cpuinfo

interrupt context

1. can not relinquish cpu by calling sleep functions

GFP_KERNEL

allocate memory:
1. GFP_KERNEL:
    kmalloc() is allowed to go to sleep and wait for pages to get freed up.

2.GFP_ATOMIC:
   Used by interrupt context code to get hold of memory. In this mode, kmalloc() is not allowed to    sleep-wait for free pages, so the probability of successful allocation with GFP_ATOMIC is lower    than with GFP_KERNEL.

2008年11月16日 星期日

df

show disk space

ex: df  -h:
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda3             9.9G  7.0G  2.4G  75% /
udev                  8.0G  132K  8.0G   1% /dev

objdump

show assembly of program:
ex:

objdump -D test.o

2008年11月13日 星期四

fsck

check file system

2008年10月30日 星期四

tethereal

ex:

tethereal -i eth7 host 192.168.5.41 -V > out

2008年10月21日 星期二

AF_UNSPEC

ai_family = AF_UNSPEC;
AF_UNSPEC: for IPv4 & IPv6

2008年10月17日 星期五

accept

#include
#include
int accept(int s, struct sockaddr *addr, socklen_t *addrlen);


return:
If successful, accept() returns a non-negative integer, which is a descriptor of the accepted socket.

2008年10月16日 星期四

2008年9月11日 星期四

scsi_execute_req

int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
                     int data_direction, void *buffer, unsigned bufflen,
                     struct scsi_sense_hdr *sshdr, int timeout, int retries)

scsi command code

include/scsi/scsi.h

READ_6   0x08
WRITE_6  0x0a

READ_10   0x28
WRITE_10  0x2a

READ_16   0x88
WRITE_16   0x8a

website about block driver

http://www.geocities.com/ravikiran_uvs/articles/

proc

read_proc

struct dentry *proc_lookup(struct inode * dir, struct dentry *dentry)

2008年9月10日 星期三

drivers/scsi/sd.c

the problem related to struct scsi_cmnd

2008年9月9日 星期二

struct scsi_cmnd

 /* These elements define the operation we are about to perform */
 #define MAX_COMMAND_SIZE        16
  unsigned char cmnd[MAX_COMMAND_SIZE];

2008年9月8日 星期一

sd_mod

remove sd_mod will delete /dev/sd*

2008年9月4日 星期四

struct scsi_sense_hdr

scsi_en.h

struct scsi_sense_hdr {         /* See SPC-3 section 4.5 */
          u8 response_code;       /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
          u8 sense_key;
          u8 asc;
          u8 ascq;
          u8 byte4;
          u8 byte5;
          u8 byte6;
          u8 additional_length;   /* always 0 for fixed sense format */
  };

2008年8月29日 星期五

random number in driver

get_random_bytes():

ex:
unsigned char uuid[16];
get_random_bytes(uuid, sizeof (uuid));

2008年8月28日 星期四

type definition

struct block_device:
linux/fs.h

dev_t:
linux/types.h

struct page:
linux/mm_types.h

struct gendisk:
linux/genhd.h

struct request_queue:
linux/blkdev.h

wait_queue_head_t:
linux/wait.h

spinlock_t:
linux/spinlock_types.h

struct semaphore:
linux/semaphore.h

2008年8月21日 星期四

dmesg

/var/log/messages

2008年8月19日 星期二

dhclient

get new ip

dm

 //The request function that just remaps the bio built up by dm_merge_bvec
static int dm_request(struct request_queue *q, struct bio *bio)
       call  __split_bio

// Split the bio into several clones.
static int __split_bio(struct mapped_device *md, struct bio *bio)
       call  __clone_and_map with parameter ci
       ( ci.sector_count= bio_sectors(bio)  )

static int __clone_and_map(struct clone_info *ci)
call  split_bvec

2008年8月18日 星期一

sector_t

typedef unsigned long sector_t;

2008年8月17日 星期日

mkfs

create filesystem
ex:
mkfs -v  /dev/hda3

struct bio

struct bio:
struct block_device  *bi_bdev;

struct bio_vec          *bi_io_vec;     /* the actual vec list */

unsigned short          bi_vcnt;        /* how many bio_vec's */

unsigned int            bi_size;        /* residual I/O count */

struct bio_vec:
  struct page     *bv_page;
  unsigned int    bv_len;
  unsigned int    bv_offset;

do I/O without request queue

three steps:
1. define a make_request function
ex:
static int sbull_make_request(request_queue_t *q, struct bio *bio) 

     in the make_request function, transfer bio & call bio_endio(struct bio *bio, unsigned int bytes, int error) to signal completion 

2. use blk_alloc_queue(GFP_KERNEL) to allocate a queue 

3. call blk_queue_make_request(request_queue_t *queue, make_request_fn *func)

when make_request function return non-zero:
the bio is submitted again. Hence, we can modify bi_bdev & starting sector to redirect bio to another device

split bio into multiple chunks:
bio_split

kthread

show kthread list
ps  -ef

2008年8月16日 星期六

interrupt

prevent interrupt entering critical section 
method 1:
 local_irq_disable();  /* Disable Interrupts in local CPU */
  /* ... Critical Section ...  */
  local_irq_enable();   /* Enable Interrupts in local CPU */

method 2:
unsigned long flags;

Point A:
  local_irq_save(flags);     /* Disable Interrupts */
  /* ... Critical Section ... */
  local_irq_restore(flags);  /* Restore state to what it was at point A */

spinlock & mutex

spinlock ensures only one thread can enter critical section
spinlock example:

#include
spinlock_t mylock = SPIN_LOCK_UNLOCKED; /* Initialize */

/* Acquire the spinlock. This is inexpensive if there
 * is no one inside the critical section. In the face of
 * contention, spinlock() has to busy-wait.
 */
spin_lock(&mylock);

/* ... Critical Section code ... */

spin_unlock(&mylock); /* Release the lock */

spinlock will busy-wait,  mutex will sleep
mutex example:
#include

/* Statically declare a mutex. To dynamically
   create a mutex, use mutex_init() */
static DEFINE_MUTEX(mymutex);

/* Acquire the mutex. This is inexpensive if there
 * is no one inside the critical section. In the face of
 * contention, mutex_lock() puts the calling thread to sleep.
 */
mutex_lock(&mymutex);

/* ... Critical Section code ... */

mutex_unlock(&mymutex);      /* Release the mutex */

linux開機設定

GRUB:
/boot/grub/grub.conf  or /boot/grub/menu.lst
grub.conf example:
default 0  #Boot the 2.6.23 kernel by default
timeout 5  #5 second to alter boot order or parameters

title kernel 2.6.23     #Boot Option 1
  #The boot image resides in the first partition of the first disk
  #under the /boot/ directory and is named vmlinuz-2.6.23. 'ro'
  #indicates that the root partition should be mounted read-only.
  kernel (hd0,0)/boot/vmlinuz-2.6.23 ro root=/dev/hda1

  #Look under section "Freeing initrd memory:387k freed"
  initrd (hd0,0)/boot/initrd

#...

LILO:
/etc/lilo.conf

compile driver

method 1:
Makefile:
      obj-m+=test.ko

make -C /usr/src/kernels/x.y.z/  M=`pwd`  modules

kernel source module

compile module:
1. cd  /usr/src/linux-x.y.z/
2. make modules

install module
1.  make modules_install

the generated module( ko)  is stored in /lib/modules/x.y.z/kernel/ 

2008年8月15日 星期五

patch

A patch is a text file containing source code differences between a development tree and the original snapshot from which the developer started work

apply patch:
ex:  if x.y.z-mm2.bz2 is a patch, go to the directory of linux source
      bzip2  -dc  ../x.y.z-mm2.bz2 |  patch -p1

create patch:
ex:
diff  -Nur   /path/originalKernal/    /path/newKernel  >  change changes.patch

global code browser

install:
http://www.gnu.org/software/global/global.html

run:
1. go to directory of source code
2. gtags
3. htags  ./codeTrace/
the generated html is in ./codeTrace/

2008年8月13日 星期三

find command

find  .  -name  "test.txt"
find text.txt under current directory

linux module location

/lib/modules/2.6.18-92.el5/kernel/drivers

2008年8月12日 星期二

HZ & jiffies

HZ是用來定義每一秒有幾次timer interrupts(time tick)

jiffies:
the number of time ticks since kernel start

ex:
unsigned long timeout=jiffies+ 3*HZ;
//  the time after 3 second
time_after(jiffies, timeout)

convert from jiffies to seconds
divide by HZ

time related methods:
time_after:  parameter is time tick 
time_before: parameter is time tick
schedule_timeout: parameter is time tick  
only schedule_timeout will give up processor

wait_event_timeout:
msleep: parameter is milliseconds

timer example( do something in the future):
#include

struct timer_list my_timer;

init_timer(&my_timer);            /* Also see setup_timer() */
my_timer.expire = jiffies + n*HZ; /* n is the timeout in number
                                     of seconds */
my_timer.function = timer_func;   /* Function to execute
                                     after n seconds */
my_timer.data = func_parameter;   /* Parameter to be passed
                                     to timer_func */
add_timer(&my_timer);             /* Start the timer */

2008年8月10日 星期日

smp

smp(多cpu)

2008年8月8日 星期五

rpm

remove rpm:
rpm -e test

query info about specific rpm
ex: 
rpm -q  test

2008年8月7日 星期四

rpm for red hat and cent os

Because red hat & cent os are related , we can get rpm for ret hat from rpm for cent os 

init network

開機網路設定:
/etc/sysconfig/network/
ifcfg-lo
ifcfg-eth0

2008年8月6日 星期三

blk_queue_make_request

 void blk_queue_make_request (request_queue_t * q, make_request_fn * mfn);

define an alternate make_request function for a device

ARGUMENTS

q

the request queue for the device to be affected
mfn
the alternate make_request function

2008年7月28日 星期一

linux driver command

lsmod 
顯示目前已經載入的模組清單

insmod 
load module into kernel
ex: insmod hello.ko

rmmod:
remove module

modprobe:
like insmod,  but also install dependent modules
(the module dependency is stored in /lib/modules/x.y.z/modules.dep)

modprobe -r:
remove module

modinfo:
show module info

linux kernel version

red hat enterprise linux 4 update 4
core_2.6.9-42.EL_i686  &  core_2.6.9-42.ELsmp_i686,  core_2.6.9-42.ELsmp_x86_64,  core_2.6.9-42.EL_x86_64

red hat enterprise linux 5 update 1
core_2.6.18-53.el5_i686  &  core_2.6.18-53.el5_x86_64

red hat enterprise linux 5 update 2
core_2.6.18-92.el5_i686  &  core_2.6.18-92.el5_x86_64

suse linux enterprise server 9

core_2.6.5-7.244-smp_x86_64


suse linux enterprise server 10 

core_2.6.16.21-0.8-smp_i686  & core_2.6.16.21-0.8-smp_x86_64


suse linux enterprise server 10 sp1

core_2.6.16.46-0.12-smp_x86_64  


suse linux enterprise server 10 sp2

core_2.6.16.60-0.21-default_i686   ,core_2.6.16.60-0.21-default_x86_64

2008年7月25日 星期五

LVM

(1) 實體磁碟 --> PV( physical volume)
1. change id to 8e
ex:
   (a) fdisk  /dev/hda
   (b) p
         show information of hda
   (c)  t -->  1 --> 8e
        modify partition 1 's id to 8e
   (d) w
         alter partition table
   (e) partprobe
         let kernel read newest partition table

2. create pv  
   (a)pvscan:
        show information of pv
   (b)pvcreate 

2008年6月4日 星期三

x11

設定開機進入X11
edit /etc/inittab
id:3:initdefault:

設定開機進入文字介面:
edit /etc/inittab
id:5:initdefault:

x11 problem:
method 1:
edit /etc/X11/xorg.conf
defaultdepth =8

2008年6月3日 星期二

iscsi-initiator-utils

start:
/etc/init.d/iscsi start

discovery lun
iscsiadm -m discovery -t sendtargets -p 192.168.5.122
192.168.5.122 is lun's ip

/etc/init.d/iscsi restart
connect to the lun 192.168.5.122,  there is a new disk , sdd( use fdisk -l to show)

Format & mount
fdisk /dev/sdd
mke2fs -j -m 0 -O dir_index /dev/sdd1
mkdir /mnt/iscsi
mount /dev/sdd1 /mnt/iscsi

2008年6月2日 星期一

yum

設定search path

/etc/yum.conf:
[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
bsoletes=1

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
#[base]
#name=Red Hat Linux $releasever - $basearch - Base
#baseurl=http://mirror.dulug.duke.edu/pub/yum-repository/redhat/$releasever/$basearch/

#[updates]
#name=Red Hat Linux $releasever - Updates
#baseurl=http://mirror.dulug.duke.edu/pub/yum-repository/redhat/updates/$releasever/

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el4/en/i386/dag/
gpgcheck=1
enabled=1

[freshrpms]
name=FreshRPMs
baseurl=http://dag.freshrpms.net/redhat/el4/en/i386/dag/
gpgcheck=1
enabled=1

[rpmfind]
name=RPMFind.net
baseurl=http://rpmfind.net/linux/dag/redhat/el4/en/i386/dag/
gpgcheck=1
enabled=1

[pdx.edu]
name=PDX.edu
baseurl=http://mirrors.cat.pdx.edu/dag/redhat/el4/en/i386/dag/
gpgcheck=1
enabled=1

Open-iSCSI

install  2.0-869.2
make

start:
rcopen-iscsi start

discovery:
iscsiadm -m discovery  -t st -p 192.168.4.123 

update chap information:
iscsiadm -m node -p 192.168.4.123 --op=update \   
--name=node.session.auth.authmethod --value=CHAP
iscsiadm -m node -p 192.168.4.123 --op=update \     --name=node.session.auth.username --value=andy
iscsiadm -m node -p 192.168.4.123 --op=update \     --name=node.session.auth.password --value=1234
login:
iscsiadm -m node -p 192.168.4.123 -l
or
iscsiadm -m node -r nodeId -l
the disk added after login is in /dev/sd*

delete record:
iscsiadm -m node -o delete
or
rm -rf /etc/iscsi/nodes/*
logout 
iscsiadm -m node -U all
daemon:
/etc/init.d/iscsi

increase iscsi ping time to prevent a lot of io error messages
node.conn[0].timeo.noop_out_interval = X
ode.conn[0].timeo.noop_out_timeout = X

2008年5月7日 星期三

open_by_devnum

struct block_device *open_by_devnum(dev_t dev, unsigned mode)

struct bio

struct bio {
    sector_t             bi_sector;  //  beginning sector
    struct bio          *bi_next;
    struct block_device *bi_bdev;
    unsigned short       bi_vcnt;
    unsigned short       bi_idx;  //  an offset into the bi_io_vec array
    struct bio_vec      *bi_io_vec;
    ...
};

generic_make_request

void generic_make_request (struct bio * bio);

make I/O requests of block devices. 
It is passed a &struct bio, which describes the I/O that needs to be done.

the success/failure status of the request, along with notification of completion,
is delivered asynchronously through the bio->bi_end_io function

The caller of generic_make_request must make sure that bi_io_vec are set to describe the memory buffer, and that bi_dev and bi_sector are set to describe the device address, and the bi_end_io and optionally bi_private are set to describe how completion notification should be signaled.

2008年5月6日 星期二

MKDEV

dev_t  a=  MKDEV( int major, int minor )

get major & minor
MIJOR( a )  &  MINOR( a)

struct gendisk

int major
int  first_minor
        first minor number associated with disk
int  minors
       range of minor numbers associated with disk. It control disk's max partition number 
char  disk_name[32]

struct gendisk *alloc_disk(int minors)

allocate gendisk 

system_utsname

add_disk

void add_disk(struct gendisk *disk);
add the disk to the list of active disks
the disk is active now

ioctl communication between kernel and user space

use block device as example:

user space program:
struct Test_info  test_info;
ioctl ( fd,  ADD,  &test_info);


driver:
1. define a function to deal with ioctl operation & assign this function 
    to struct block_device_operations
     ex: 
     define a function  test_ioctl
     struct block_device_operations test_ops;
     test_ops.ioctl = test_ioctl       

2.  define the function to deal with ioctl operation
     it will receive two important parameters.
     One is command, the other is argument.
     From out example,  the command received is ADD, the parameter received is &test_info

3.  copy data from user space to kernel space
     use copy_from_user

copy_from_user

copy_from_user(void *to, const void *from, long n);
to: point to kernel-space address
from :  point to user-space address

2008年5月5日 星期一

function stat

int  stat(const char *restrict pathstruct stat *restrict buf);

get file status

struct stat {
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
off_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
blksize_t st_blksize;
blkcnt_t st_blocks;
mode_t st_attr;
}; 

2008年5月4日 星期日

structure sg_io_hdr_t


getopt

getopt(int argcchar * const argv[]const char *optstring)
get option character from command line argument list

ex:getopt(argc, argv, “bf:")
     options are b & f

strdup

char *  strdup(const char *s1); 
allocates sufficient memory for a copy of the string s1, 
does the copy, and returns a pointer to it.

strstr

strstr(const char *s1, const char *s2);
locate a substring in a string

struct utsname & uname

struct utsname
hold information returned by the uname function

uname(struct utsname *name)
store information identifying the current system in the structure pointed to by name.

2008年4月30日 星期三

vnc

start:
vncserver