2019年02月08日
情報科学類 オペレーティングシステム II
筑波大学 システム情報系
新城 靖
<yas@cs.tsukuba.ac.jp>
このページは、次の URL にあります。
http://www.coins.tsukuba.ac.jp/~yas/coins/os2-2018/2019-02-08
あるいは、次のページから手繰っていくこともできます。
http://www.coins.tsukuba.ac.jp/~yas/
http://www.cs.tsukuba.ac.jp/~yas/
試験について
Linux では、割り込みの処理を2つに分ける。
図? 割り込み処理の前半部分と後半部分
割り込みハンドラ(前半部)と後半部の役割分担の目安。
注意1: Tasklet は、task 構造体とはまったく関係ない。名前がよくない。
注意2: Softirq という用語を、割り込み処理の後半部という意味で使う人もい る。
注意3: 伝統的なUnixでは、top half は、システム・コールから派生する上位 層の処理、bottom half は、割り込みから派生する下位層の処理の意味で使わ れることがある。Linux では、top half, bottom half は、割り込み処理の前 半部分と後半部分の意味に使う。
Tasklet で1つの仕事は次のような、struct tasklet_struct で表現される。
linux-4.20/include/linux/interrupt.h
542: struct tasklet_struct
543: {
544: struct tasklet_struct *next;
545: unsigned long state;
546: atomic_t count;
547: void (*func)(unsigned long);
548: unsigned long data;
549: };
図? Taskletにおける仕事のキュー
DECLARE_TASKLET(name, func, data)
有効な(count==0) の struct tasklet_struct を宣言する
DECLARE_TASKLET_DISABLED(name, func, data)
無効な(count==1) の struct tasklet_struct を宣言する
void tasklet_init(struct tasklet_struct *t,
void (*func)(unsigned long), unsigned long data);
その他に、生成消滅有効無効に関して次のような操作がある。
void tasklet_handler(unsigned long data) {
...
}
void tasklet_schedule(struct tasklet_struct *t)
Tasklet t を通常の優先度でスケジュールする
void tasklet_hi_schedule(struct tasklet_struct *t)
Tasklet t を高優先度でスケジュールする
すると、それは「そのうちに」1度だけ実行される。
linux-4.20/drivers/net/wireless/ath/ath9k/ath9k.h
994: struct ath_softc {
...
1002: struct tasklet_struct intr_tq;
1003: struct tasklet_struct bcon_tasklet;
...
1091: };
linux-4.20/drivers/net/wireless/ath/ath9k/init.c
651: static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
652: const struct ath_bus_ops *bus_ops)
653: {
...
733: tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
734: tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
735: (unsigned long)sc);
...
793: }
linux-4.20/drivers/net/wireless/ath/ath9k/main.c
481: irqreturn_t ath_isr(int irq, void *dev)
482: {
...
499: struct ath_softc *sc = dev;
...
504: bool sched = false;
...
524: ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */
...
543: if (status & SCHED_INTR)
544: sched = true;
...
557: if (status & ATH9K_INT_SWBA)
558: tasklet_schedule(&sc->bcon_tasklet);
...
585: if (sched) {
586: /* turn off every interrupt */
587: ath9k_hw_kill_interrupts(ah);
588: tasklet_schedule(&sc->intr_tq);
589: }
590:
591: return IRQ_HANDLED;
...
594: }
linux-4.20/drivers/net/wireless/ath/ath9k/main.c
371: void ath9k_tasklet(unsigned long data)
372: {
...
479: }
linux-4.20/drivers/net/wireless/ath/ath9k/beacon.c
388: void ath9k_beacon_tasklet(unsigned long data)
389: {
...
508: }
図? Work Queueにおける仕事のキュー
キューにつながれる仕事は、Tasklet の仕事とほとんど同じで、関数へのポイ ンタ func と data からなる。処理の主体が、ワーカ・スレッドと呼ばれるカー ネル・レベルのスレッドである所が違う。
$ ps alx|egrep events
1 0 19 2 20 0 0 0 worker S ? 0:12 [events/0]
1 0 20 2 20 0 0 0 worker S ? 0:08 [events/1]
1 0 21 2 20 0 0 0 worker S ? 0:08 [events/2]
1 0 22 2 20 0 0 0 worker S ? 0:10 [events/3]
0 1013 3242 2450 20 0 105236 900 pipe_w S+ pts/3 0:00 egrep events
$
汎用の Work Queue のワーカ・スレッドの他に、専用のワーカ・スレッドを作
ることもできる。
linux-4.20/include/linux/workqueue.h
21: typedef void (*work_func_t)(struct work_struct *work);
102: struct work_struct {
103: atomic_long_t data;
104: struct list_head entry;
105: work_func_t func;
...
109: };
struct work_struct my_work; ... INIT_WORK(&my_work,my_work_handler);
void my_work_handler(struct work_struct *work)
{
...
}
schedule_work(&work);
この結果、INIT_WORK() で設定したハンドラがワーカ・スレッドにより「その
うち」に呼び出される。
schedule_work() では、即座に実行される可能性もある。少し後に実行したい (間を取りたい)時には、次の関数を呼ぶ。
schedule_delayed_work(&work,ticks);
ticks は、どのくらい間をとるか。単位は、
ticks (jiffiesの単位)。
多くのシステムで10ミリ秒-1ミリ秒で、設定によって異なる。
解決策:
図? 層構造を用いたファイル・システムの実装
解決策
$ ls -l /usr/bin/perl{,5.10.1}
-rwxr-xr-x. 2 root root 13304 Mar 22 2017 /usr/bin/perl
-rwxr-xr-x. 2 root root 13304 Mar 22 2017 /usr/bin/perl5.10.1
$ ls -li /usr/bin/perl{,5.10.1}
1846686 -rwxr-xr-x. 2 root root 13304 Mar 22 2017 /usr/bin/perl
1846686 -rwxr-xr-x. 2 root root 13304 Mar 22 2017 /usr/bin/perl5.10.1
$
$ grep -v '#' /etc/fstab
UUID=9cfbc67e-781c-48d1-8303-1dde8ce87ee9 / ext4 defaults 1 1
UUID=bab1faf1-5f5b-4a2a-b24f-e850a2b0b82d /boot ext4 defaults 1 2
UUID=a1f61ff2-2c99-4c54-8c3e-2178eed3ec10 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
pentas-fs:/vol0/home /home nfs rw,hard,bg,nfsvers=3,intr 0 0
pentas-fs:/vol0/web /var/www nfs rw,hard,bg,nfsvers=3,intr 0 0
pentas-fs:/vol0/local3 /usr/local3 nfs rw,hard,bg,nfsvers=3,intr 0 0
$ df /
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 49071944 6721604 39857568 15% /
$ blkid /dev/sda3
/dev/sda3: UUID="9cfbc67e-781c-48d1-8303-1dde8ce87ee9" TYPE="ext4"
$ ls -l /dev/sda3
brw-rw----. 1 root disk 8, 3 Feb 2 10:50 /dev/sda3
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
|-sda1 8:1 0 512M 0 part /boot
|-sda2 8:2 0 2G 0 part [SWAP]
`-sda3 8:3 0 47.6G 0 part /
sr0 11:0 1 1024M 0 rom
$ ls -l /dev/sda
brw-rw----. 1 root disk 8, 0 Feb 2 10:50 /dev/sda
$
$ grep cd /etc/auto.misc
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
$
STAT(2) Linux Programmer's Manual STAT(2)
...
int stat(const char *path, struct stat *buf);
...
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for filesystem I/O */
blkcnt_t st_blocks; /* number of blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
};
stat コマンドを使うと stat システム・コールで返される値に近いものが表示
される。
$ stat .bashrc
File: `.bashrc'
Size: 240 Blocks: 16 IO Block: 65536 regular file
Device: 14h/20d Inode: 50700660 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1013/ yas) Gid: ( 510/ prof)
Access: 2019-01-27 15:29:58.000000000 +0900
Modify: 2018-06-08 10:46:57.004451000 +0900
Change: 2018-06-08 10:46:57.004451000 +0900
$
図? スーパーブロック、inode、dentry、file
int fd1 = open("file1",O_RDONLY);
int fd2 = open("file1",O_RDONLY);
ファイル名 "file1" で表現されるファイルの inode 構造体は、1 個でも、
file 構造体は、2 個割り当てられる。
ディスク上には対応するデータ構造は存在しない。
linux-4.20/include/linux/fs.h
901: struct file {
...
906: struct path f_path;
907: struct inode *f_inode; /* cached value */
908: const struct file_operations *f_op;
...
916: atomic_long_t f_count;
...
920: loff_t f_pos;
...
930: void *private_data;
...
937: struct address_space *f_mapping;
...
939: } __randomize_layout
940: __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
linux-4.20/include/linux/path.h
8: struct path {
9: struct vfsmount *mnt;
10: struct dentry *dentry;
11: } __randomize_layout;



図? C言語によるオブジェクト指向の継承・委譲の実装方法。共通インスタンス変数・関数、固有インスタンス変数関数の置き方
struct fileの操作は、たとえば次のような形で行われる。 第1引数は、struct file *。
struct file *file;
file->f_op->read(file, buf, count, pos);
f_op には、次のような手続きがある。各ファイルシステム
(ext4,nfs,tmpfs,...) ごとに、手続きの実体は異なるが、インタフェースは同じ。
linux-4.20/include/linux/fs.h
1777: struct file_operations {
1778: struct module *owner;
1779: loff_t (*llseek) (struct file *, loff_t, int);
1780: ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
1781: ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
1782: ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
1783: ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
1784: int (*iterate) (struct file *, struct dir_context *);
1785: int (*iterate_shared) (struct file *, struct dir_context *);
1786: __poll_t (*poll) (struct file *, struct poll_table_struct *);
1787: long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
1788: long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
1789: int (*mmap) (struct file *, struct vm_area_struct *);
1790: unsigned long mmap_supported_flags;
1791: int (*open) (struct inode *, struct file *);
1792: int (*flush) (struct file *, fl_owner_t id);
1793: int (*release) (struct inode *, struct file *);
1794: int (*fsync) (struct file *, loff_t, loff_t, int datasync);
1795: int (*fasync) (int, struct file *, int);
1796: int (*lock) (struct file *, int, struct file_lock *);
1797: ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
1798: unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
1799: int (*check_flags)(int);
1800: int (*flock) (struct file *, int, struct file_lock *);
1801: ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
1802: ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
1803: int (*setlease)(struct file *, long, struct file_lock **, void **);
1804: long (*fallocate)(struct file *file, int mode, loff_t offset,
1805: loff_t len);
1806: void (*show_fdinfo)(struct seq_file *m, struct file *f);
1807: #ifndef CONFIG_MMU
1808: unsigned (*mmap_capabilities)(struct file *);
1809: #endif
1810: ssize_t (*copy_file_range)(struct file *, loff_t, struct file *,
1811: loff_t, size_t, unsigned int);
1812: loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in,
1813: struct file *file_out, loff_t pos_out,
1814: loff_t len, unsigned int remap_flags);
1815: int (*fadvise)(struct file *, loff_t, loff_t, int);
1816: } __randomize_layout;
主な手続きの意味
linux-4.20/include/linux/dcache.h
88: struct dentry {
...
93: struct dentry *d_parent; /* parent directory */
94: struct qstr d_name;
95: struct inode *d_inode; /* Where the name belongs to - NULL is
96: * negative */
97: unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
98:
99: /* Ref lookup also touches following */
100: struct lockref d_lockref; /* per-dentry lock and refcount */
101: const struct dentry_operations *d_op;
102: struct super_block *d_sb; /* The root of the dentry tree */
...
104: void *d_fsdata; /* fs-specific data */
...
110: struct list_head d_child; /* child of parent list */
111: struct list_head d_subdirs; /* our children */
...
120: } __randomize_layout;
284: static inline unsigned d_count(const struct dentry *dentry)
285: {
286: return dentry->d_lockref.count;
287: }
33: #define HASH_LEN_DECLARE u32 hash; u32 len
47: struct qstr {
48: union {
49: struct {
50: HASH_LEN_DECLARE;
51: };
52: u64 hash_len;
53: };
54: const unsigned char *name;
55: };
82: # define DNAME_INLINE_LEN 40 /* 128 bytes */
linux-4.20/include/linux/fs.h
603: struct inode {
604: umode_t i_mode;
605: unsigned short i_opflags;
606: kuid_t i_uid;
607: kgid_t i_gid;
...
615: const struct inode_operations *i_op;
616: struct super_block *i_sb;
...
624: unsigned long i_ino;
...
633: const unsigned int i_nlink;
...
636: dev_t i_rdev;
637: loff_t i_size;
638: struct timespec64 i_atime;
639: struct timespec64 i_mtime;
640: struct timespec64 i_ctime;
641: spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
642: unsigned short i_bytes;
643: u8 i_blkbits;
644: u8 i_write_hint;
645: blkcnt_t i_blocks;
...
658: struct hlist_node i_hash;
...
672: struct hlist_head i_dentry;
...
676: atomic_t i_count;
...
705: void *i_private; /* fs or device private pointer */
706: } __randomize_layout;
struct inode *inode;
...
inode->i_op->create(inode, name, mode, true);
i_op には、次のような手続きがある。各ファイルシステム
(ext4,nfs,tmpfs,...) ごとに、手続きの実体は異なるが、インタフェースは同じ。
linux-4.20/include/linux/fs.h
1818: struct inode_operations {
1819: struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
1820: const char * (*get_link) (struct dentry *, struct inode *, struct delayed_call *);
1821: int (*permission) (struct inode *, int);
1822: struct posix_acl * (*get_acl)(struct inode *, int);
1823:
1824: int (*readlink) (struct dentry *, char __user *,int);
1825:
1826: int (*create) (struct inode *,struct dentry *, umode_t, bool);
1827: int (*link) (struct dentry *,struct inode *,struct dentry *);
1828: int (*unlink) (struct inode *,struct dentry *);
1829: int (*symlink) (struct inode *,struct dentry *,const char *);
1830: int (*mkdir) (struct inode *,struct dentry *,umode_t);
1831: int (*rmdir) (struct inode *,struct dentry *);
1832: int (*mknod) (struct inode *,struct dentry *,umode_t,dev_t);
1833: int (*rename) (struct inode *, struct dentry *,
1834: struct inode *, struct dentry *, unsigned int);
1835: int (*setattr) (struct dentry *, struct iattr *);
1836: int (*getattr) (const struct path *, struct kstat *, u32, unsigned int);
1837: ssize_t (*listxattr) (struct dentry *, char *, size_t);
1838: int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
1839: u64 len);
1840: int (*update_time)(struct inode *, struct timespec64 *, int);
1841: int (*atomic_open)(struct inode *, struct dentry *,
1842: struct file *, unsigned open_flag,
1843: umode_t create_mode);
1844: int (*tmpfile) (struct inode *, struct dentry *, umode_t);
1845: int (*set_acl)(struct inode *, struct posix_acl *, int);
1846: } ____cacheline_aligned;
linux-4.20/include/linux/fs.h
1379: struct super_block {
...
1384: loff_t s_maxbytes; /* Max file size */
1385: struct file_system_type *s_type;
1386: const struct super_operations *s_op;
...
1393: struct dentry *s_root;
...
1420: void *s_fs_info; /* Filesystem private info */
...
1480: struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
1481: struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
...
1494: struct list_head s_inodes; /* all inodes */
...
1498: } __randomize_layout;
p->files->fdt->fd[fd] の struct file を表
す。開いているファイルの数が小さい時は、
p->files->fd_array[fd]と同じ。
多くのファイルを開くプロセスでは、
p->files->fd_array[NR_OPEN_DEFAULT]で足りなくなった時は、
expand_files(), expand_fdtable() で拡張する。
これらの関数では、kmalloc() 等でメモリを割り当てる。
linux-4.20/include/linux/sched.h
590: struct task_struct {
...
867: struct files_struct *files;
...
1224: };
linux-4.20/include/linux/fdtable.h
24: #define NR_OPEN_DEFAULT BITS_PER_LONG
...
48: struct files_struct {
...
56: struct fdtable __rcu *fdt;
57: struct fdtable fdtab;
...
66: struct file __rcu * fd_array[NR_OPEN_DEFAULT];
67: };
linux-4.20/include/asm-generic/bitsperlong.h
8: #ifdef CONFIG_64BIT
9: #define BITS_PER_LONG 64
10: #else
11: #define BITS_PER_LONG 32
12: #endif /* CONFIG_64BIT */
図? task_struct、ファイル記述子、file構造体、その他
linux-4.20/fs/read_write.c
586: SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
587: {
588: return ksys_read(fd, buf, count);
589: }
571: ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
572: {
573: struct fd f = fdget_pos(fd);
574: ssize_t ret = -EBADF;
575:
576: if (f.file) {
577: loff_t pos = file_pos_read(f.file);
578: ret = vfs_read(f.file, buf, count, &pos);
579: if (ret >= 0)
580: file_pos_write(f.file, pos);
581: fdput_pos(f);
582: }
583: return ret;
584: }
linux-4.20/include/linux/file.h
33: struct fd {
34: struct file *file;
35: unsigned int flags;
36: };
linux-4.20/fs/read_write.c
437: ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
438: {
439: ssize_t ret;
440:
441: if (!(file->f_mode & FMODE_READ))
442: return -EBADF;
443: if (!(file->f_mode & FMODE_CAN_READ))
444: return -EINVAL;
445: if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
446: return -EFAULT;
447:
448: ret = rw_verify_area(READ, file, pos, count);
449: if (!ret) {
450: if (count > MAX_RW_COUNT)
451: count = MAX_RW_COUNT;
452: ret = __vfs_read(file, buf, count, pos);
453: if (ret > 0) {
454: fsnotify_access(file);
455: add_rchar(current, ret);
456: }
457: inc_syscr(current);
458: }
459:
460: return ret;
461: }
412: ssize_t __vfs_read(struct file *file, char __user *buf, size_t count,
413: loff_t *pos)
414: {
415: if (file->f_op->read)
416: return file->f_op->read(file, buf, count, pos);
417: else if (file->f_op->read_iter)
418: return new_sync_read(file, buf, count, pos);
419: else
420: return -EINVAL;
421: }
395: static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
396: {
...
406: ret = call_read_iter(filp, &kiocb, &iter);
...
408: *ppos = kiocb.ki_pos;
409: return ret;
410: }
linux-4.20/include/linux/fs.h
1848: static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio,
1849: struct iov_iter *iter)
1850: {
1851: return file->f_op->read_iter(kio, iter);
1852: }
linux-4.20/fs/ext4/file.c
497: const struct file_operations ext4_file_operations = {
498: .llseek = ext4_llseek,
499: .read_iter = ext4_file_read_iter,
500: .write_iter = ext4_file_write_iter,
501: .unlocked_ioctl = ext4_ioctl,
502: #ifdef CONFIG_COMPAT
503: .compat_ioctl = ext4_compat_ioctl,
504: #endif
505: .mmap = ext4_file_mmap,
506: .mmap_supported_flags = MAP_SYNC,
507: .open = ext4_file_open,
508: .release = ext4_release_file,
509: .fsync = ext4_sync_file,
510: .get_unmapped_area = thp_get_unmapped_area,
511: .splice_read = generic_file_splice_read,
512: .splice_write = iter_file_splice_write,
513: .fallocate = ext4_fallocate,
514: };
515:
516: const struct inode_operations ext4_file_inode_operations = {
...
523: };
linux-4.20/fs/ext4/super.c
1370: static const struct super_operations ext4_sops = {
...
1390: };
linux-4.20/fs/ext4/ext4.h
924: struct ext4_inode_info {
...
991: struct inode vfs_inode;
...
1067: };
1516: static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
1517: {
1518: return container_of(inode, struct ext4_inode_info, vfs_inode);
1519: }
linux-4.20/include/linux/kernel.h
988: /**
989: * container_of - cast a member of a structure out to the containing structure
990: * @ptr: the pointer to the member.
991: * @type: the type of the container struct this is embedded in.
992: * @member: the name of the member within the struct.
993: *
994: */
995: #define container_of(ptr, type, member) ({ \
996: void *__mptr = (void *)(ptr); \
997: BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
998: !__same_type(*(ptr), void), \
999: "pointer type mismatch in container_of()"); \
1000: ((type *)(__mptr - offsetof(type, member))); })

図? Ext4 ファイルシステムで使う構造体 ext4_inode_info での struct inode の保持
linux-4.20/fs/ext4/file.c
65: static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
66: {
...
77: return generic_file_read_iter(iocb, to);
78: }
linux-4.20/mm/filemap.c
2238: ssize_t
2239: generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
2240: {
...
2289: retval = generic_file_buffered_read(iocb, iter, retval);
2290: out:
2291: return retval;
2292: }
linux-4.20/mm/filemap.c
1977: static ssize_t generic_file_buffered_read(struct kiocb *iocb,
1978: struct iov_iter *iter, ssize_t written)
1979: {
1980: struct file *filp = iocb->ki_filp;
1981: struct address_space *mapping = filp->f_mapping;
1982: struct inode *inode = mapping->host;
1983: struct file_ra_state *ra = &filp->f_ra;
1984: loff_t *ppos = &iocb->ki_pos;
1985: pgoff_t index;
...
1988: unsigned long offset; /* offset into pagecache page */
...
1990: int error = 0;
...
1996: index = *ppos >> PAGE_SHIFT;
...
2000: offset = *ppos & ~PAGE_MASK;
...
2002: for (;;) {
2003: struct page *page;
...
2006: unsigned long nr, ret;
...
2009: find_page:
...
2015: page = find_get_page(mapping, index);
2016: if (!page) {
...
2019: page_cache_sync_readahead(mapping,
2020: ra, filp,
2021: index, last_index - index);
2022: page = find_get_page(mapping, index);
2023: if (unlikely(page == NULL))
2024: goto no_cached_page;
2025: }
...
2064: page_ok:
...
2082: nr = PAGE_SIZE;
...
2090: nr = nr - offset;
...
2112: ret = copy_page_to_iter(page, offset, nr, iter);
2113: offset += ret;
2114: index += offset >> PAGE_SHIFT;
2115: offset &= ~PAGE_MASK;
...
2118: put_page(page);
2119: written += ret;
2120: if (!iov_iter_count(iter))
2121: goto out;
...
2128: page_not_up_to_date:
...
2134: page_not_up_to_date_locked:
...
2148: readpage:
...
2195: no_cached_page:
...
2216: }
...
2220: out:
...
2225: *ppos = ((loff_t)index << PAGE_SHIFT) + offset;
2226: file_accessed(filp);
2227: return written ? written : error;
2228: }
void f(int arg1, int arg2) {
省略;
}
これを実現するために、どのような Tasklet のハンドラと初期化コードを書け
ばよいか。以下の空欄を埋めなさい。
static struct tasklet_struct tl1;
void tasklet_handler(unsigned long data) { /* Tasklet ハンドラ */
int arg1, arg2;
arg1 = 省略;
arg2 = 省略;
/*空欄(a)*/
その他の仕事;
}
初期化
{
/*空欄(b)*/(&tl1, /*空欄(c)*/, 0 );
}
irqreturn_t irq_handler(int irq, void *dev) {
/*空欄(d)*/
return IRQ_HANDLED;
}
int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync)
{
struct inode *inode = file->f_mapping->host;
if (!file->f_op->/*空欄(e)*/)
return -EINVAL;
/*中略*/
return file->f_op->/*空欄(f)*/(/*空欄(g)*/, start, end, datasync);
}