aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2010-08-15 12:52:59 -0400
committerArnd Bergmann <arnd@arndb.de>2010-10-15 09:53:27 -0400
commit6038f373a3dc1f1c26496e60b6c40b164716f07e (patch)
treea0d3bbd026eea41b9fc36b8c722cbaf56cd9f825 /drivers/scsi
parent1ec5584e3edf9c4bf2c88c846534d19cf986ba11 (diff)
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make nonseekable_open the default for future file operations without a .llseek pointer. The three cases that we can automatically detect are no_llseek, seq_lseek and default_llseek. For cases where we can we can automatically prove that the file offset is always ignored, we use noop_llseek, which maintains the current behavior of not returning an error from a seek. New drivers should normally not use noop_llseek but instead use no_llseek and call nonseekable_open at open time. Existing drivers can be converted to do the same when the maintainer knows for certain that no user code relies on calling seek on the device file. The generated code is often incorrectly indented and right now contains comments that clarify for each added line why a specific variant was chosen. In the version that gets submitted upstream, the comments will be gone and I will manually fix the indentation, because there does not seem to be a way to do that using coccinelle. Some amount of new code is currently sitting in linux-next that should get the same modifications, which I will do at the end of the merge window. Many thanks to Julia Lawall for helping me learn to write a semantic patch that does all this. ===== begin semantic patch ===== // This adds an llseek= method to all file operations, // as a preparation for making no_llseek the default. // // The rules are // - use no_llseek explicitly if we do nonseekable_open // - use seq_lseek for sequential files // - use default_llseek if we know we access f_pos // - use noop_llseek if we know we don't access f_pos, // but we still want to allow users to call lseek // @ open1 exists @ identifier nested_open; @@ nested_open(...) { <+... nonseekable_open(...) ...+> } @ open exists@ identifier open_f; identifier i, f; identifier open1.nested_open; @@ int open_f(struct inode *i, struct file *f) { <+... ( nonseekable_open(...) | nested_open(...) ) ...+> } @ read disable optional_qualifier exists @ identifier read_f; identifier f, p, s, off; type ssize_t, size_t, loff_t; expression E; identifier func; @@ ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off) { <+... ( *off = E | *off += E | func(..., off, ...) | E = *off ) ...+> } @ read_no_fpos disable optional_qualifier exists @ identifier read_f; identifier f, p, s, off; type ssize_t, size_t, loff_t; @@ ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off) { ... when != off } @ write @ identifier write_f; identifier f, p, s, off; type ssize_t, size_t, loff_t; expression E; identifier func; @@ ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off) { <+... ( *off = E | *off += E | func(..., off, ...) | E = *off ) ...+> } @ write_no_fpos @ identifier write_f; identifier f, p, s, off; type ssize_t, size_t, loff_t; @@ ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off) { ... when != off } @ fops0 @ identifier fops; @@ struct file_operations fops = { ... }; @ has_llseek depends on fops0 @ identifier fops0.fops; identifier llseek_f; @@ struct file_operations fops = { ... .llseek = llseek_f, ... }; @ has_read depends on fops0 @ identifier fops0.fops; identifier read_f; @@ struct file_operations fops = { ... .read = read_f, ... }; @ has_write depends on fops0 @ identifier fops0.fops; identifier write_f; @@ struct file_operations fops = { ... .write = write_f, ... }; @ has_open depends on fops0 @ identifier fops0.fops; identifier open_f; @@ struct file_operations fops = { ... .open = open_f, ... }; // use no_llseek if we call nonseekable_open //////////////////////////////////////////// @ nonseekable1 depends on !has_llseek && has_open @ identifier fops0.fops; identifier nso ~= "nonseekable_open"; @@ struct file_operations fops = { ... .open = nso, ... +.llseek = no_llseek, /* nonseekable */ }; @ nonseekable2 depends on !has_llseek @ identifier fops0.fops; identifier open.open_f; @@ struct file_operations fops = { ... .open = open_f, ... +.llseek = no_llseek, /* open uses nonseekable */ }; // use seq_lseek for sequential files ///////////////////////////////////// @ seq depends on !has_llseek @ identifier fops0.fops; identifier sr ~= "seq_read"; @@ struct file_operations fops = { ... .read = sr, ... +.llseek = seq_lseek, /* we have seq_read */ }; // use default_llseek if there is a readdir /////////////////////////////////////////// @ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @ identifier fops0.fops; identifier readdir_e; @@ // any other fop is used that changes pos struct file_operations fops = { ... .readdir = readdir_e, ... +.llseek = default_llseek, /* readdir is present */ }; // use default_llseek if at least one of read/write touches f_pos ///////////////////////////////////////////////////////////////// @ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @ identifier fops0.fops; identifier read.read_f; @@ // read fops use offset struct file_operations fops = { ... .read = read_f, ... +.llseek = default_llseek, /* read accesses f_pos */ }; @ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @ identifier fops0.fops; identifier write.write_f; @@ // write fops use offset struct file_operations fops = { ... .write = write_f, ... + .llseek = default_llseek, /* write accesses f_pos */ }; // Use noop_llseek if neither read nor write accesses f_pos /////////////////////////////////////////////////////////// @ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @ identifier fops0.fops; identifier read_no_fpos.read_f; identifier write_no_fpos.write_f; @@ // write fops use offset struct file_operations fops = { ... .write = write_f, .read = read_f, ... +.llseek = noop_llseek, /* read and write both use no f_pos */ }; @ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @ identifier fops0.fops; identifier write_no_fpos.write_f; @@ struct file_operations fops = { ... .write = write_f, ... +.llseek = noop_llseek, /* write uses no f_pos */ }; @ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @ identifier fops0.fops; identifier read_no_fpos.read_f; @@ struct file_operations fops = { ... .read = read_f, ... +.llseek = noop_llseek, /* read uses no f_pos */ }; @ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @ identifier fops0.fops; @@ struct file_operations fops = { ... +.llseek = noop_llseek, /* no read or write fn */ }; ===== End semantic patch ===== Signed-off-by: Arnd Bergmann <arnd@arndb.de> Cc: Julia Lawall <julia@diku.dk> Cc: Christoph Hellwig <hch@infradead.org>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/3w-9xxx.c3
-rw-r--r--drivers/scsi/3w-sas.c3
-rw-r--r--drivers/scsi/3w-xxxx.c3
-rw-r--r--drivers/scsi/aacraid/linit.c1
-rw-r--r--drivers/scsi/ch.c1
-rw-r--r--drivers/scsi/dpt_i2o.c1
-rw-r--r--drivers/scsi/gdth.c1
-rw-r--r--drivers/scsi/megaraid.c1
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c1
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c1
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_ctl.c1
-rw-r--r--drivers/scsi/osd/osd_uld.c1
-rw-r--r--drivers/scsi/pmcraid.c1
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c1
-rw-r--r--drivers/scsi/scsi_tgt_if.c1
-rw-r--r--drivers/scsi/sg.c1
16 files changed, 19 insertions, 3 deletions
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index e20b7bdd4c78..67aad69cfbc2 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -222,7 +222,8 @@ static const struct file_operations twa_fops = {
222 .owner = THIS_MODULE, 222 .owner = THIS_MODULE,
223 .unlocked_ioctl = twa_chrdev_ioctl, 223 .unlocked_ioctl = twa_chrdev_ioctl,
224 .open = twa_chrdev_open, 224 .open = twa_chrdev_open,
225 .release = NULL 225 .release = NULL,
226 .llseek = noop_llseek,
226}; 227};
227 228
228/* This function will complete an aen request from the isr */ 229/* This function will complete an aen request from the isr */
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index f481e734aad4..7afac93d889f 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -890,7 +890,8 @@ static const struct file_operations twl_fops = {
890 .owner = THIS_MODULE, 890 .owner = THIS_MODULE,
891 .unlocked_ioctl = twl_chrdev_ioctl, 891 .unlocked_ioctl = twl_chrdev_ioctl,
892 .open = twl_chrdev_open, 892 .open = twl_chrdev_open,
893 .release = NULL 893 .release = NULL,
894 .llseek = noop_llseek,
894}; 895};
895 896
896/* This function passes sense data from firmware to scsi layer */ 897/* This function passes sense data from firmware to scsi layer */
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 30d735ad35b5..5a2337306037 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1059,7 +1059,8 @@ static const struct file_operations tw_fops = {
1059 .owner = THIS_MODULE, 1059 .owner = THIS_MODULE,
1060 .unlocked_ioctl = tw_chrdev_ioctl, 1060 .unlocked_ioctl = tw_chrdev_ioctl,
1061 .open = tw_chrdev_open, 1061 .open = tw_chrdev_open,
1062 .release = NULL 1062 .release = NULL,
1063 .llseek = noop_llseek,
1063}; 1064};
1064 1065
1065/* This function will free up device extension resources */ 1066/* This function will free up device extension resources */
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index cad6f9abaeb9..13af86eec96e 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1039,6 +1039,7 @@ static const struct file_operations aac_cfg_fops = {
1039 .compat_ioctl = aac_compat_cfg_ioctl, 1039 .compat_ioctl = aac_compat_cfg_ioctl,
1040#endif 1040#endif
1041 .open = aac_cfg_open, 1041 .open = aac_cfg_open,
1042 .llseek = noop_llseek,
1042}; 1043};
1043 1044
1044static struct scsi_host_template aac_driver_template = { 1045static struct scsi_host_template aac_driver_template = {
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index d6532187f616..e40c9f7a002a 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -981,6 +981,7 @@ static const struct file_operations changer_fops = {
981#ifdef CONFIG_COMPAT 981#ifdef CONFIG_COMPAT
982 .compat_ioctl = ch_ioctl_compat, 982 .compat_ioctl = ch_ioctl_compat,
983#endif 983#endif
984 .llseek = noop_llseek,
984}; 985};
985 986
986static int __init init_ch_module(void) 987static int __init init_ch_module(void)
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index ffc1edf5e80d..7a61206ed1c0 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -126,6 +126,7 @@ static const struct file_operations adpt_fops = {
126#ifdef CONFIG_COMPAT 126#ifdef CONFIG_COMPAT
127 .compat_ioctl = compat_adpt_ioctl, 127 .compat_ioctl = compat_adpt_ioctl,
128#endif 128#endif
129 .llseek = noop_llseek,
129}; 130};
130 131
131/* Structures and definitions for synchronous message posting. 132/* Structures and definitions for synchronous message posting.
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index b860d650a563..9886586df01f 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -372,6 +372,7 @@ static const struct file_operations gdth_fops = {
372 .unlocked_ioctl = gdth_unlocked_ioctl, 372 .unlocked_ioctl = gdth_unlocked_ioctl,
373 .open = gdth_open, 373 .open = gdth_open,
374 .release = gdth_close, 374 .release = gdth_close,
375 .llseek = noop_llseek,
375}; 376};
376 377
377#include "gdth_proc.h" 378#include "gdth_proc.h"
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 0b6e3228610a..aac80f7bb999 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -101,6 +101,7 @@ static const struct file_operations megadev_fops = {
101 .owner = THIS_MODULE, 101 .owner = THIS_MODULE,
102 .unlocked_ioctl = megadev_unlocked_ioctl, 102 .unlocked_ioctl = megadev_unlocked_ioctl,
103 .open = megadev_open, 103 .open = megadev_open,
104 .llseek = noop_llseek,
104}; 105};
105 106
106/* 107/*
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index 41f82f76d884..ab801232d777 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -75,6 +75,7 @@ static const struct file_operations lsi_fops = {
75 .compat_ioctl = mraid_mm_compat_ioctl, 75 .compat_ioctl = mraid_mm_compat_ioctl,
76#endif 76#endif
77 .owner = THIS_MODULE, 77 .owner = THIS_MODULE,
78 .llseek = noop_llseek,
78}; 79};
79 80
80static struct miscdevice megaraid_mm_dev = { 81static struct miscdevice megaraid_mm_dev = {
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 99e4478c3f3e..209cc87b9a32 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -3957,6 +3957,7 @@ static const struct file_operations megasas_mgmt_fops = {
3957#ifdef CONFIG_COMPAT 3957#ifdef CONFIG_COMPAT
3958 .compat_ioctl = megasas_mgmt_compat_ioctl, 3958 .compat_ioctl = megasas_mgmt_compat_ioctl,
3959#endif 3959#endif
3960 .llseek = noop_llseek,
3960}; 3961};
3961 3962
3962/* 3963/*
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index b774973f0765..9a4e584ae3cc 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -2952,6 +2952,7 @@ static const struct file_operations ctl_fops = {
2952#ifdef CONFIG_COMPAT 2952#ifdef CONFIG_COMPAT
2953 .compat_ioctl = _ctl_ioctl_compat, 2953 .compat_ioctl = _ctl_ioctl_compat,
2954#endif 2954#endif
2955 .llseek = noop_llseek,
2955}; 2956};
2956 2957
2957static struct miscdevice ctl_dev = { 2958static struct miscdevice ctl_dev = {
diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c
index ffdd9fdb9995..b31a8e3841d7 100644
--- a/drivers/scsi/osd/osd_uld.c
+++ b/drivers/scsi/osd/osd_uld.c
@@ -182,6 +182,7 @@ static const struct file_operations osd_fops = {
182 .open = osd_uld_open, 182 .open = osd_uld_open,
183 .release = osd_uld_release, 183 .release = osd_uld_release,
184 .unlocked_ioctl = osd_uld_ioctl, 184 .unlocked_ioctl = osd_uld_ioctl,
185 .llseek = noop_llseek,
185}; 186};
186 187
187struct osd_dev *osduld_path_lookup(const char *name) 188struct osd_dev *osduld_path_lookup(const char *name)
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index ecc45c8b4e6b..4b8765785aeb 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -4165,6 +4165,7 @@ static const struct file_operations pmcraid_fops = {
4165#ifdef CONFIG_COMPAT 4165#ifdef CONFIG_COMPAT
4166 .compat_ioctl = pmcraid_chr_ioctl, 4166 .compat_ioctl = pmcraid_chr_ioctl,
4167#endif 4167#endif
4168 .llseek = noop_llseek,
4168}; 4169};
4169 4170
4170 4171
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 1e4bff695254..9946fac54255 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -3948,6 +3948,7 @@ static struct pci_driver qla2xxx_pci_driver = {
3948 3948
3949static struct file_operations apidev_fops = { 3949static struct file_operations apidev_fops = {
3950 .owner = THIS_MODULE, 3950 .owner = THIS_MODULE,
3951 .llseek = noop_llseek,
3951}; 3952};
3952 3953
3953/** 3954/**
diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index a87e21c35ef2..bbb02f6e917c 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -333,6 +333,7 @@ static const struct file_operations tgt_fops = {
333 .poll = tgt_poll, 333 .poll = tgt_poll,
334 .write = tgt_write, 334 .write = tgt_write,
335 .mmap = tgt_mmap, 335 .mmap = tgt_mmap,
336 .llseek = noop_llseek,
336}; 337};
337 338
338static struct miscdevice tgt_miscdev = { 339static struct miscdevice tgt_miscdev = {
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 78d616315d8e..00baea1e2dbf 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1351,6 +1351,7 @@ static const struct file_operations sg_fops = {
1351 .mmap = sg_mmap, 1351 .mmap = sg_mmap,
1352 .release = sg_release, 1352 .release = sg_release,
1353 .fasync = sg_fasync, 1353 .fasync = sg_fasync,
1354 .llseek = no_llseek,
1354}; 1355};
1355 1356
1356static struct class *sg_sysfs_class; 1357static struct class *sg_sysfs_class;