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
14#include "init.h"14#include "init.h"
15#include "user.h"15#include "user.h"
16#include "mode.h"16#include "mode.h"
17#include "kern_constants.h"
17 18
18struct aio_thread_req {19struct aio_thread_req {
19 enum aio_type type;20 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
65static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf,66static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf,
66 int len, unsigned long long offset, struct aio_context *aio)67 int len, unsigned long long offset, struct aio_context *aio)
67{68{
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 });
69 char c;76 char c;
70 int err;
71 77
72 iocb = ((struct iocb) { .aio_data = (unsigned long) aio,78 switch (type) {
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){
83 case AIO_READ:79 case AIO_READ:
84 iocb.aio_lio_opcode = IOCB_CMD_PREAD;80 iocbp->aio_lio_opcode = IOCB_CMD_PREAD;
85 err = io_submit(ctx, 1, &iocbp);
86 break;81 break;
87 case AIO_WRITE:82 case AIO_WRITE:
88 iocb.aio_lio_opcode = IOCB_CMD_PWRITE;83 iocbp->aio_lio_opcode = IOCB_CMD_PWRITE;
89 err = io_submit(ctx, 1, &iocbp);
90 break;84 break;
91 case AIO_MMAP:85 case AIO_MMAP:
92 iocb.aio_lio_opcode = IOCB_CMD_PREAD;86 iocbp->aio_lio_opcode = IOCB_CMD_PREAD;
93 iocb.aio_buf = (unsigned long) &c;87 iocbp->aio_buf = (unsigned long) &c;
94 iocb.aio_nbytes = sizeof(c);88 iocbp->aio_nbytes = sizeof(c);
95 err = io_submit(ctx, 1, &iocbp);
96 break;89 break;
97 default:90 default:
98 printk("Bogus op in do_aio - %d\n", type);91 printk(UM_KERN_ERR "Bogus op in do_aio - %d\n", type);
99 err = -EINVAL;92 return -EINVAL;
100 break;
101 }93 }
102 94
103 if(err > 0)95 return (io_submit(ctx, 1, &iocbp) > 0) ? 0 : -errno;
104 err = 0;
105 else
106 err = -errno;
107
108 return err;
109}96}
110 97
111/* Initialized in an initcall and unchanged thereafter */98/* Initialized in an initcall and unchanged thereafter */