aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390
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/s390
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/s390')
-rw-r--r--drivers/s390/block/dasd_eer.c1
-rw-r--r--drivers/s390/char/fs3270.c1
-rw-r--r--drivers/s390/char/monreader.c1
-rw-r--r--drivers/s390/char/monwriter.c1
-rw-r--r--drivers/s390/char/tape_char.c1
-rw-r--r--drivers/s390/char/vmcp.c1
-rw-r--r--drivers/s390/char/vmlogrdr.c1
-rw-r--r--drivers/s390/char/vmwatchdog.c1
-rw-r--r--drivers/s390/char/zcore.c2
-rw-r--r--drivers/s390/cio/chsc_sch.c1
-rw-r--r--drivers/s390/cio/css.c1
-rw-r--r--drivers/s390/crypto/zcrypt_api.c3
-rw-r--r--drivers/s390/scsi/zfcp_cfdc.c3
13 files changed, 16 insertions, 2 deletions
diff --git a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
index 7158f9528ecc..c71d89dba302 100644
--- a/drivers/s390/block/dasd_eer.c
+++ b/drivers/s390/block/dasd_eer.c
@@ -670,6 +670,7 @@ static const struct file_operations dasd_eer_fops = {
670 .read = &dasd_eer_read, 670 .read = &dasd_eer_read,
671 .poll = &dasd_eer_poll, 671 .poll = &dasd_eer_poll,
672 .owner = THIS_MODULE, 672 .owner = THIS_MODULE,
673 .llseek = noop_llseek,
673}; 674};
674 675
675static struct miscdevice *dasd_eer_dev = NULL; 676static struct miscdevice *dasd_eer_dev = NULL;
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index 857dfcb7b359..eb28fb01a38a 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -520,6 +520,7 @@ static const struct file_operations fs3270_fops = {
520 .compat_ioctl = fs3270_ioctl, /* ioctl */ 520 .compat_ioctl = fs3270_ioctl, /* ioctl */
521 .open = fs3270_open, /* open */ 521 .open = fs3270_open, /* open */
522 .release = fs3270_close, /* release */ 522 .release = fs3270_close, /* release */
523 .llseek = no_llseek,
523}; 524};
524 525
525/* 526/*
diff --git a/drivers/s390/char/monreader.c b/drivers/s390/char/monreader.c
index e021ec663ef9..5b8b8592d311 100644
--- a/drivers/s390/char/monreader.c
+++ b/drivers/s390/char/monreader.c
@@ -447,6 +447,7 @@ static const struct file_operations mon_fops = {
447 .release = &mon_close, 447 .release = &mon_close,
448 .read = &mon_read, 448 .read = &mon_read,
449 .poll = &mon_poll, 449 .poll = &mon_poll,
450 .llseek = noop_llseek,
450}; 451};
451 452
452static struct miscdevice mon_dev = { 453static struct miscdevice mon_dev = {
diff --git a/drivers/s390/char/monwriter.c b/drivers/s390/char/monwriter.c
index 572a1e7fd099..e0702d3ea33b 100644
--- a/drivers/s390/char/monwriter.c
+++ b/drivers/s390/char/monwriter.c
@@ -274,6 +274,7 @@ static const struct file_operations monwrite_fops = {
274 .open = &monwrite_open, 274 .open = &monwrite_open,
275 .release = &monwrite_close, 275 .release = &monwrite_close,
276 .write = &monwrite_write, 276 .write = &monwrite_write,
277 .llseek = noop_llseek,
277}; 278};
278 279
279static struct miscdevice mon_dev = { 280static struct miscdevice mon_dev = {
diff --git a/drivers/s390/char/tape_char.c b/drivers/s390/char/tape_char.c
index 539045acaad4..883e2db02bd3 100644
--- a/drivers/s390/char/tape_char.c
+++ b/drivers/s390/char/tape_char.c
@@ -53,6 +53,7 @@ static const struct file_operations tape_fops =
53#endif 53#endif
54 .open = tapechar_open, 54 .open = tapechar_open,
55 .release = tapechar_release, 55 .release = tapechar_release,
56 .llseek = no_llseek,
56}; 57};
57 58
58static int tapechar_major = TAPECHAR_MAJOR; 59static int tapechar_major = TAPECHAR_MAJOR;
diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c
index 04e532eec032..0e7cb1a84151 100644
--- a/drivers/s390/char/vmcp.c
+++ b/drivers/s390/char/vmcp.c
@@ -177,6 +177,7 @@ static const struct file_operations vmcp_fops = {
177 .write = vmcp_write, 177 .write = vmcp_write,
178 .unlocked_ioctl = vmcp_ioctl, 178 .unlocked_ioctl = vmcp_ioctl,
179 .compat_ioctl = vmcp_ioctl, 179 .compat_ioctl = vmcp_ioctl,
180 .llseek = no_llseek,
180}; 181};
181 182
182static struct miscdevice vmcp_dev = { 183static struct miscdevice vmcp_dev = {
diff --git a/drivers/s390/char/vmlogrdr.c b/drivers/s390/char/vmlogrdr.c
index e40a1b892866..0d6dc4b92cc2 100644
--- a/drivers/s390/char/vmlogrdr.c
+++ b/drivers/s390/char/vmlogrdr.c
@@ -97,6 +97,7 @@ static const struct file_operations vmlogrdr_fops = {
97 .open = vmlogrdr_open, 97 .open = vmlogrdr_open,
98 .release = vmlogrdr_release, 98 .release = vmlogrdr_release,
99 .read = vmlogrdr_read, 99 .read = vmlogrdr_read,
100 .llseek = no_llseek,
100}; 101};
101 102
102 103
diff --git a/drivers/s390/char/vmwatchdog.c b/drivers/s390/char/vmwatchdog.c
index e13508c98b1a..12ef9121d4f0 100644
--- a/drivers/s390/char/vmwatchdog.c
+++ b/drivers/s390/char/vmwatchdog.c
@@ -297,6 +297,7 @@ static const struct file_operations vmwdt_fops = {
297 .unlocked_ioctl = &vmwdt_ioctl, 297 .unlocked_ioctl = &vmwdt_ioctl,
298 .write = &vmwdt_write, 298 .write = &vmwdt_write,
299 .owner = THIS_MODULE, 299 .owner = THIS_MODULE,
300 .llseek = noop_llseek,
300}; 301};
301 302
302static struct miscdevice vmwdt_dev = { 303static struct miscdevice vmwdt_dev = {
diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c
index f5ea3384a4b9..3b94044027c2 100644
--- a/drivers/s390/char/zcore.c
+++ b/drivers/s390/char/zcore.c
@@ -459,6 +459,7 @@ static const struct file_operations zcore_memmap_fops = {
459 .read = zcore_memmap_read, 459 .read = zcore_memmap_read,
460 .open = zcore_memmap_open, 460 .open = zcore_memmap_open,
461 .release = zcore_memmap_release, 461 .release = zcore_memmap_release,
462 .llseek = no_llseek,
462}; 463};
463 464
464static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf, 465static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
@@ -486,6 +487,7 @@ static const struct file_operations zcore_reipl_fops = {
486 .write = zcore_reipl_write, 487 .write = zcore_reipl_write,
487 .open = zcore_reipl_open, 488 .open = zcore_reipl_open,
488 .release = zcore_reipl_release, 489 .release = zcore_reipl_release,
490 .llseek = no_llseek,
489}; 491};
490 492
491#ifdef CONFIG_32BIT 493#ifdef CONFIG_32BIT
diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c
index a83877c664a6..f2b77e7bfc6f 100644
--- a/drivers/s390/cio/chsc_sch.c
+++ b/drivers/s390/cio/chsc_sch.c
@@ -806,6 +806,7 @@ static const struct file_operations chsc_fops = {
806 .open = nonseekable_open, 806 .open = nonseekable_open,
807 .unlocked_ioctl = chsc_ioctl, 807 .unlocked_ioctl = chsc_ioctl,
808 .compat_ioctl = chsc_ioctl, 808 .compat_ioctl = chsc_ioctl,
809 .llseek = no_llseek,
809}; 810};
810 811
811static struct miscdevice chsc_misc_device = { 812static struct miscdevice chsc_misc_device = {
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index ac94ac751459..ca8e1c240c3c 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -1067,6 +1067,7 @@ static ssize_t cio_settle_write(struct file *file, const char __user *buf,
1067static const struct file_operations cio_settle_proc_fops = { 1067static const struct file_operations cio_settle_proc_fops = {
1068 .open = nonseekable_open, 1068 .open = nonseekable_open,
1069 .write = cio_settle_write, 1069 .write = cio_settle_write,
1070 .llseek = no_llseek,
1070}; 1071};
1071 1072
1072static int __init cio_settle_init(void) 1073static int __init cio_settle_init(void)
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 41e0aaefafd5..f5221749d180 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -897,7 +897,8 @@ static const struct file_operations zcrypt_fops = {
897 .compat_ioctl = zcrypt_compat_ioctl, 897 .compat_ioctl = zcrypt_compat_ioctl,
898#endif 898#endif
899 .open = zcrypt_open, 899 .open = zcrypt_open,
900 .release = zcrypt_release 900 .release = zcrypt_release,
901 .llseek = no_llseek,
901}; 902};
902 903
903/* 904/*
diff --git a/drivers/s390/scsi/zfcp_cfdc.c b/drivers/s390/scsi/zfcp_cfdc.c
index fcbd2b756da4..1838cda68ba8 100644
--- a/drivers/s390/scsi/zfcp_cfdc.c
+++ b/drivers/s390/scsi/zfcp_cfdc.c
@@ -251,8 +251,9 @@ static const struct file_operations zfcp_cfdc_fops = {
251 .open = nonseekable_open, 251 .open = nonseekable_open,
252 .unlocked_ioctl = zfcp_cfdc_dev_ioctl, 252 .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
253#ifdef CONFIG_COMPAT 253#ifdef CONFIG_COMPAT
254 .compat_ioctl = zfcp_cfdc_dev_ioctl 254 .compat_ioctl = zfcp_cfdc_dev_ioctl,
255#endif 255#endif
256 .llseek = no_llseek,
256}; 257};
257 258
258struct miscdevice zfcp_cfdc_misc = { 259struct miscdevice zfcp_cfdc_misc = {