Commit 8bc92afcf7f5c598001dd04e62d88f57f6e89e51

Authored by Kent Overstreet
Committed by Benjamin LaHaise
1 parent 73a7075e3f

aio: Kill unneeded kiocb members

The old aio retry infrastucture needed to save the various arguments to
to aio operations. But with the retry infrastructure gone, we can trim
struct kiocb quite a bit.

Signed-off-by: Kent Overstreet <koverstreet@google.com>
Cc: Zach Brown <zab@redhat.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Asai Thambi S P <asamymuthupa@micron.com>
Cc: Selvan Mani <smani@micron.com>
Cc: Sam Bradshaw <sbradshaw@micron.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>

Showing 2 changed files with 42 additions and 38 deletions Side-by-side Diff

... ... @@ -723,8 +723,6 @@
723 723 eventfd_ctx_put(req->ki_eventfd);
724 724 if (req->ki_dtor)
725 725 req->ki_dtor(req);
726   - if (req->ki_iovec != &req->ki_inline_vec)
727   - kfree(req->ki_iovec);
728 726 kmem_cache_free(kiocb_cachep, req);
729 727 }
730 728  
731 729  
732 730  
733 731  
... ... @@ -1054,24 +1052,26 @@
1054 1052 typedef ssize_t (aio_rw_op)(struct kiocb *, const struct iovec *,
1055 1053 unsigned long, loff_t);
1056 1054  
1057   -static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
  1055 +static ssize_t aio_setup_vectored_rw(struct kiocb *kiocb,
  1056 + int rw, char __user *buf,
  1057 + unsigned long *nr_segs,
  1058 + struct iovec **iovec,
  1059 + bool compat)
1058 1060 {
1059 1061 ssize_t ret;
1060 1062  
1061   - kiocb->ki_nr_segs = kiocb->ki_nbytes;
  1063 + *nr_segs = kiocb->ki_nbytes;
1062 1064  
1063 1065 #ifdef CONFIG_COMPAT
1064 1066 if (compat)
1065 1067 ret = compat_rw_copy_check_uvector(rw,
1066   - (struct compat_iovec __user *)kiocb->ki_buf,
1067   - kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
1068   - &kiocb->ki_iovec);
  1068 + (struct compat_iovec __user *)buf,
  1069 + *nr_segs, 1, *iovec, iovec);
1069 1070 else
1070 1071 #endif
1071 1072 ret = rw_copy_check_uvector(rw,
1072   - (struct iovec __user *)kiocb->ki_buf,
1073   - kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
1074   - &kiocb->ki_iovec);
  1073 + (struct iovec __user *)buf,
  1074 + *nr_segs, 1, *iovec, iovec);
1075 1075 if (ret < 0)
1076 1076 return ret;
1077 1077  
1078 1078  
1079 1079  
... ... @@ -1080,15 +1080,17 @@
1080 1080 return 0;
1081 1081 }
1082 1082  
1083   -static ssize_t aio_setup_single_vector(int rw, struct kiocb *kiocb)
  1083 +static ssize_t aio_setup_single_vector(struct kiocb *kiocb,
  1084 + int rw, char __user *buf,
  1085 + unsigned long *nr_segs,
  1086 + struct iovec *iovec)
1084 1087 {
1085   - if (unlikely(!access_ok(!rw, kiocb->ki_buf, kiocb->ki_nbytes)))
  1088 + if (unlikely(!access_ok(!rw, buf, kiocb->ki_nbytes)))
1086 1089 return -EFAULT;
1087 1090  
1088   - kiocb->ki_iovec = &kiocb->ki_inline_vec;
1089   - kiocb->ki_iovec->iov_base = kiocb->ki_buf;
1090   - kiocb->ki_iovec->iov_len = kiocb->ki_nbytes;
1091   - kiocb->ki_nr_segs = 1;
  1091 + iovec->iov_base = buf;
  1092 + iovec->iov_len = kiocb->ki_nbytes;
  1093 + *nr_segs = 1;
1092 1094 return 0;
1093 1095 }
1094 1096  
1095 1097  
1096 1098  
1097 1099  
... ... @@ -1097,15 +1099,18 @@
1097 1099 * Performs the initial checks and aio retry method
1098 1100 * setup for the kiocb at the time of io submission.
1099 1101 */
1100   -static ssize_t aio_run_iocb(struct kiocb *req, bool compat)
  1102 +static ssize_t aio_run_iocb(struct kiocb *req, unsigned opcode,
  1103 + char __user *buf, bool compat)
1101 1104 {
1102 1105 struct file *file = req->ki_filp;
1103 1106 ssize_t ret;
  1107 + unsigned long nr_segs;
1104 1108 int rw;
1105 1109 fmode_t mode;
1106 1110 aio_rw_op *rw_op;
  1111 + struct iovec inline_vec, *iovec = &inline_vec;
1107 1112  
1108   - switch (req->ki_opcode) {
  1113 + switch (opcode) {
1109 1114 case IOCB_CMD_PREAD:
1110 1115 case IOCB_CMD_PREADV:
1111 1116 mode = FMODE_READ;
1112 1117  
1113 1118  
... ... @@ -1126,16 +1131,21 @@
1126 1131 if (!rw_op)
1127 1132 return -EINVAL;
1128 1133  
1129   - ret = (req->ki_opcode == IOCB_CMD_PREADV ||
1130   - req->ki_opcode == IOCB_CMD_PWRITEV)
1131   - ? aio_setup_vectored_rw(rw, req, compat)
1132   - : aio_setup_single_vector(rw, req);
  1134 + ret = (opcode == IOCB_CMD_PREADV ||
  1135 + opcode == IOCB_CMD_PWRITEV)
  1136 + ? aio_setup_vectored_rw(req, rw, buf, &nr_segs,
  1137 + &iovec, compat)
  1138 + : aio_setup_single_vector(req, rw, buf, &nr_segs,
  1139 + iovec);
1133 1140 if (ret)
1134 1141 return ret;
1135 1142  
1136 1143 ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
1137   - if (ret < 0)
  1144 + if (ret < 0) {
  1145 + if (iovec != &inline_vec)
  1146 + kfree(iovec);
1138 1147 return ret;
  1148 + }
1139 1149  
1140 1150 req->ki_nbytes = ret;
1141 1151  
... ... @@ -1149,8 +1159,7 @@
1149 1159 if (rw == WRITE)
1150 1160 file_start_write(file);
1151 1161  
1152   - ret = rw_op(req, req->ki_iovec,
1153   - req->ki_nr_segs, req->ki_pos);
  1162 + ret = rw_op(req, iovec, nr_segs, req->ki_pos);
1154 1163  
1155 1164 if (rw == WRITE)
1156 1165 file_end_write(file);
... ... @@ -1175,6 +1184,9 @@
1175 1184 return -EINVAL;
1176 1185 }
1177 1186  
  1187 + if (iovec != &inline_vec)
  1188 + kfree(iovec);
  1189 +
1178 1190 if (ret != -EIOCBQUEUED) {
1179 1191 /*
1180 1192 * There's no easy way to restart the syscall since other AIO's
1181 1193  
1182 1194  
... ... @@ -1246,12 +1258,11 @@
1246 1258 req->ki_obj.user = user_iocb;
1247 1259 req->ki_user_data = iocb->aio_data;
1248 1260 req->ki_pos = iocb->aio_offset;
1249   -
1250   - req->ki_buf = (char __user *)(unsigned long)iocb->aio_buf;
1251 1261 req->ki_nbytes = iocb->aio_nbytes;
1252   - req->ki_opcode = iocb->aio_lio_opcode;
1253 1262  
1254   - ret = aio_run_iocb(req, compat);
  1263 + ret = aio_run_iocb(req, iocb->aio_lio_opcode,
  1264 + (char __user *)(unsigned long)iocb->aio_buf,
  1265 + compat);
1255 1266 if (ret)
1256 1267 goto out_put_req;
1257 1268  
... ... @@ -36,6 +36,7 @@
36 36 struct kioctx *ki_ctx; /* NULL for sync ops */
37 37 kiocb_cancel_fn *ki_cancel;
38 38 void (*ki_dtor)(struct kiocb *);
  39 + void *private;
39 40  
40 41 union {
41 42 void __user *user;
... ... @@ -44,15 +45,7 @@
44 45  
45 46 __u64 ki_user_data; /* user's data for completion */
46 47 loff_t ki_pos;
47   -
48   - void *private;
49   - /* State that we remember to be able to restart/retry */
50   - unsigned short ki_opcode;
51   - size_t ki_nbytes; /* copy of iocb->aio_nbytes */
52   - char __user *ki_buf; /* remaining iocb->aio_buf */
53   - struct iovec ki_inline_vec; /* inline vector */
54   - struct iovec *ki_iovec;
55   - unsigned long ki_nr_segs;
  48 + size_t ki_nbytes; /* copy of iocb->aio_nbytes */
56 49  
57 50 struct list_head ki_list; /* the aio core uses this
58 51 * for cancellation */