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.
Unified · Split
| @@ -14,6 +14,7 @@ · 13 unmodified lines | ||
| 14 | 14 | #include "init.h" |
| 15 | 15 | #include "user.h" |
| 16 | 16 | #include "mode.h" |
| 17 | +#include "kern_constants.h" | |
| 17 | 18 | |
| 18 | 19 | struct aio_thread_req { |
| 19 | 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 | ||
| 65 | 66 | static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf, |
| 66 | 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 | 76 | char c; |
| 70 | − int err; | |
| 71 | 77 | |
| 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) { | |
| 83 | 79 | 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; | |
| 86 | 81 | break; |
| 87 | 82 | 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; | |
| 90 | 84 | break; |
| 91 | 85 | 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); | |
| 96 | 89 | break; |
| 97 | 90 | 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; | |
| 101 | 93 | } |
| 102 | 94 | |
| 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; | |
| 109 | 96 | } |
| 110 | 97 | |
| 111 | 98 | /* Initialized in an initcall and unchanged thereafter */ |