History

uml: fix aio compilation bug

Restructure do_aio thanks to commments from Ulrich and Al. Uli started this by seeing that UML's initialization of a struct iocb initialized fields that it shouldn't. Al followed up by adding the following cleanups: eliminating a variable by just using an anonymous structure in its place. hoisting a duplicated line out of the switch. simplifying the error checking at the end. I added a severity to the printk.

Jeff Dike committed 19 years ago

Commit da3e30e1 parent 1a65f491 file · +17 −30Browse files

Unified · Split

arch/um/os-Linux/aio.c+17−30
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include "init.h"
1515 #include "user.h"
1616 #include "mode.h"
17+#include "kern_constants.h"
1718
1819 struct aio_thread_req {
1920 enum aio_type type;
@@ -65,47 +66,33 @@ static long io_getevents(aio_context_t ctx_id, long min_nr, long nr, · 45 unmodified lines
6566 static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf,
6667 int len, unsigned long long offset, struct aio_context *aio)
6768 {
68− struct iocb iocb, *iocbp = &iocb;
69+ struct iocb *iocbp = & ((struct iocb) {
70+ .aio_data = (unsigned long) aio,
71+ .aio_fildes = fd,
72+ .aio_buf = (unsigned long) buf,
73+ .aio_nbytes = len,
74+ .aio_offset = offset
75+ });
6976 char c;
70− int err;
7177
72− iocb = ((struct iocb) { .aio_data = (unsigned long) aio,
73− .aio_reqprio = 0,
74− .aio_fildes = fd,
75− .aio_buf = (unsigned long) buf,
76− .aio_nbytes = len,
77− .aio_offset = offset,
78− .aio_reserved1 = 0,
79− .aio_reserved2 = 0,
80− .aio_reserved3 = 0 });
81−
82− switch(type){
78+ switch (type) {
8379 case AIO_READ:
84− iocb.aio_lio_opcode = IOCB_CMD_PREAD;
85− err = io_submit(ctx, 1, &iocbp);
80+ iocbp->aio_lio_opcode = IOCB_CMD_PREAD;
8681 break;
8782 case AIO_WRITE:
88− iocb.aio_lio_opcode = IOCB_CMD_PWRITE;
89− err = io_submit(ctx, 1, &iocbp);
83+ iocbp->aio_lio_opcode = IOCB_CMD_PWRITE;
9084 break;
9185 case AIO_MMAP:
92− iocb.aio_lio_opcode = IOCB_CMD_PREAD;
93− iocb.aio_buf = (unsigned long) &c;
94− iocb.aio_nbytes = sizeof(c);
95− err = io_submit(ctx, 1, &iocbp);
86+ iocbp->aio_lio_opcode = IOCB_CMD_PREAD;
87+ iocbp->aio_buf = (unsigned long) &c;
88+ iocbp->aio_nbytes = sizeof(c);
9689 break;
9790 default:
98− printk("Bogus op in do_aio - %d\n", type);
99− err = -EINVAL;
100− break;
91+ printk(UM_KERN_ERR "Bogus op in do_aio - %d\n", type);
92+ return -EINVAL;
10193 }
10294
103− if(err > 0)
104− err = 0;
105− else
106− err = -errno;
107−
108− return err;
95+ return (io_submit(ctx, 1, &iocbp) > 0) ? 0 : -errno;
10996 }
11097
11198 /* Initialized in an initcall and unchanged thereafter */