Use a single ITER_XARRAY iterator to describe the portion of a file to be transmitted to the server rather than generating a series of small ITER_BVEC iterators on the fly. This will make it easier to implement AIO in afs. In theory we could maybe use one giant ITER_BVEC, but that means potentially allocating a huge array of bio_vec structs (max 256 per page) when in fact the pagecache already has a structure listing all the relevant pages (radix_tree/xarray) that can be walked over.
Unified · Split
| @@ -1055,8 +1055,7 @@ static const struct afs_call_type afs_RXFSStoreData64 = { · 1054 unmodified lines | ||
| 1055 | 1055 | /* |
| 1056 | 1056 | * store a set of pages to a very large file |
| 1057 | 1057 | */ |
| 1058 | −static void afs_fs_store_data64(struct afs_operation *op, | |
| 1059 | − loff_t pos, loff_t size, loff_t i_size) | |
| 1058 | +static void afs_fs_store_data64(struct afs_operation *op) | |
| 1060 | 1059 | { |
| 1061 | 1060 | struct afs_vnode_param *vp = &op->file[0]; |
| 1062 | 1061 | struct afs_call *call; |
| @@ -1071,7 +1070,7 @@ static void afs_fs_store_data64(struct afs_operation *op, · 8 unmodified lines | ||
| 1071 | 1070 | if (!call) |
| 1072 | 1071 | return afs_op_nomem(op); |
| 1073 | 1072 | |
| 1074 | − call->send_pages = true; | |
| 1073 | + call->write_iter = op->store.write_iter; | |
| 1075 | 1074 | |
| 1076 | 1075 | /* marshall the parameters */ |
| 1077 | 1076 | bp = call->request; |
| @@ -1087,47 +1086,38 @@ static void afs_fs_store_data64(struct afs_operation *op, · 9 unmodified lines | ||
| 1087 | 1086 | *bp++ = 0; /* unix mode */ |
| 1088 | 1087 | *bp++ = 0; /* segment size */ |
| 1089 | 1088 | |
| 1090 | − *bp++ = htonl(upper_32_bits(pos)); | |
| 1091 | − *bp++ = htonl(lower_32_bits(pos)); | |
| 1092 | − *bp++ = htonl(upper_32_bits(size)); | |
| 1093 | − *bp++ = htonl(lower_32_bits(size)); | |
| 1094 | − *bp++ = htonl(upper_32_bits(i_size)); | |
| 1095 | − *bp++ = htonl(lower_32_bits(i_size)); | |
| 1089 | + *bp++ = htonl(upper_32_bits(op->store.pos)); | |
| 1090 | + *bp++ = htonl(lower_32_bits(op->store.pos)); | |
| 1091 | + *bp++ = htonl(upper_32_bits(op->store.size)); | |
| 1092 | + *bp++ = htonl(lower_32_bits(op->store.size)); | |
| 1093 | + *bp++ = htonl(upper_32_bits(op->store.i_size)); | |
| 1094 | + *bp++ = htonl(lower_32_bits(op->store.i_size)); | |
| 1096 | 1095 | |
| 1097 | 1096 | trace_afs_make_fs_call(call, &vp->fid); |
| 1098 | 1097 | afs_make_op_call(op, call, GFP_NOFS); |
| 1099 | 1098 | } |
| 1100 | 1099 | |
| 1101 | 1100 | /* |
| 1102 | − * store a set of pages | |
| 1101 | + * Write data to a file on the server. | |
| 1103 | 1102 | */ |
| 1104 | 1103 | void afs_fs_store_data(struct afs_operation *op) |
| 1105 | 1104 | { |
| 1106 | 1105 | struct afs_vnode_param *vp = &op->file[0]; |
| 1107 | 1106 | struct afs_call *call; |
| 1108 | − loff_t size, pos, i_size; | |
| 1109 | 1107 | __be32 *bp; |
| 1110 | 1108 | |
| 1111 | 1109 | _enter(",%x,{%llx:%llu},,", |
| 1112 | 1110 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
| 1113 | 1111 | |
| 1114 | − size = (loff_t)op->store.last_to - (loff_t)op->store.first_offset; | |
| 1115 | − if (op->store.first != op->store.last) | |
| 1116 | − size += (loff_t)(op->store.last - op->store.first) << PAGE_SHIFT; | |
| 1117 | − pos = (loff_t)op->store.first << PAGE_SHIFT; | |
| 1118 | − pos += op->store.first_offset; | |
| 1119 | − | |
| 1120 | − i_size = i_size_read(&vp->vnode->vfs_inode); | |
| 1121 | − if (pos + size > i_size) | |
| 1122 | − i_size = size + pos; | |
| 1123 | − | |
| 1124 | 1112 | _debug("size %llx, at %llx, i_size %llx", |
| 1125 | − (unsigned long long) size, (unsigned long long) pos, | |
| 1126 | − (unsigned long long) i_size); | |
| 1113 | + (unsigned long long)op->store.size, | |
| 1114 | + (unsigned long long)op->store.pos, | |
| 1115 | + (unsigned long long)op->store.i_size); | |
| 1127 | 1116 | |
| 1128 | − if (upper_32_bits(pos) || upper_32_bits(i_size) || upper_32_bits(size) || | |
| 1129 | − upper_32_bits(pos + size)) | |
| 1130 | − return afs_fs_store_data64(op, pos, size, i_size); | |
| 1117 | + if (upper_32_bits(op->store.pos) || | |
| 1118 | + upper_32_bits(op->store.size) || | |
| 1119 | + upper_32_bits(op->store.i_size)) | |
| 1120 | + return afs_fs_store_data64(op); | |
| 1131 | 1121 | |
| 1132 | 1122 | call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData, |
| 1133 | 1123 | (4 + 6 + 3) * 4, |
| @@ -1135,7 +1125,7 @@ void afs_fs_store_data(struct afs_operation *op) · 1 unmodified line | ||
| 1135 | 1125 | if (!call) |
| 1136 | 1126 | return afs_op_nomem(op); |
| 1137 | 1127 | |
| 1138 | − call->send_pages = true; | |
| 1128 | + call->write_iter = op->store.write_iter; | |
| 1139 | 1129 | |
| 1140 | 1130 | /* marshall the parameters */ |
| 1141 | 1131 | bp = call->request; |
| @@ -1151,9 +1141,9 @@ void afs_fs_store_data(struct afs_operation *op) · 9 unmodified lines | ||
| 1151 | 1141 | *bp++ = 0; /* unix mode */ |
| 1152 | 1142 | *bp++ = 0; /* segment size */ |
| 1153 | 1143 | |
| 1154 | − *bp++ = htonl(lower_32_bits(pos)); | |
| 1155 | − *bp++ = htonl(lower_32_bits(size)); | |
| 1156 | − *bp++ = htonl(lower_32_bits(i_size)); | |
| 1144 | + *bp++ = htonl(lower_32_bits(op->store.pos)); | |
| 1145 | + *bp++ = htonl(lower_32_bits(op->store.size)); | |
| 1146 | + *bp++ = htonl(lower_32_bits(op->store.i_size)); | |
| 1157 | 1147 | |
| 1158 | 1148 | trace_afs_make_fs_call(call, &vp->fid); |
| 1159 | 1149 | afs_make_op_call(op, call, GFP_NOFS); |
| @@ -107,6 +107,7 @@ struct afs_call { · 106 unmodified lines | ||
| 107 | 107 | void *request; /* request data (first part) */ |
| 108 | 108 | size_t iov_len; /* Size of *iter to be used */ |
| 109 | 109 | struct iov_iter def_iter; /* Default buffer/data iterator */ |
| 110 | + struct iov_iter *write_iter; /* Iterator defining write to be made */ | |
| 110 | 111 | struct iov_iter *iter; /* Iterator currently in use */ |
| 111 | 112 | union { /* Convenience for ->def_iter */ |
| 112 | 113 | struct kvec kvec[1]; |
| @@ -133,7 +134,6 @@ struct afs_call { · 20 unmodified lines | ||
| 133 | 134 | unsigned char unmarshall; /* unmarshalling phase */ |
| 134 | 135 | unsigned char addr_ix; /* Address in ->alist */ |
| 135 | 136 | bool drop_ref; /* T if need to drop ref for incoming call */ |
| 136 | − bool send_pages; /* T if data from mapping should be sent */ | |
| 137 | 137 | bool need_attention; /* T if RxRPC poked us */ |
| 138 | 138 | bool async; /* T if asynchronous */ |
| 139 | 139 | bool upgrade; /* T to request service upgrade */ |
| @@ -811,12 +811,13 @@ struct afs_operation { · 671 unmodified lines | ||
| 811 | 811 | afs_lock_type_t type; |
| 812 | 812 | } lock; |
| 813 | 813 | struct { |
| 814 | − struct address_space *mapping; /* Pages being written from */ | |
| 815 | − pgoff_t first; /* first page in mapping to deal with */ | |
| 816 | − pgoff_t last; /* last page in mapping to deal with */ | |
| 817 | − unsigned first_offset; /* offset into mapping[first] */ | |
| 818 | − unsigned last_to; /* amount of mapping[last] */ | |
| 819 | − bool laundering; /* Laundering page, PG_writeback not set */ | |
| 814 | + struct iov_iter *write_iter; | |
| 815 | + loff_t pos; | |
| 816 | + loff_t size; | |
| 817 | + loff_t i_size; | |
| 818 | + pgoff_t first; /* first page in mapping to deal with */ | |
| 819 | + pgoff_t last; /* last page in mapping to deal with */ | |
| 820 | + bool laundering; /* Laundering page, PG_writeback not set */ | |
| 820 | 821 | } store; |
| 821 | 822 | struct { |
| 822 | 823 | struct iattr *attr; |
| @@ -271,40 +271,6 @@ void afs_flat_call_destructor(struct afs_call *call) · 270 unmodified lines | ||
| 271 | 271 | call->buffer = NULL; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | −#define AFS_BVEC_MAX 8 | |
| 275 | − | |
| 276 | −/* | |
| 277 | − * Load the given bvec with the next few pages. | |
| 278 | − */ | |
| 279 | −static void afs_load_bvec(struct afs_call *call, struct msghdr *msg, | |
| 280 | − struct bio_vec *bv, pgoff_t first, pgoff_t last, | |
| 281 | − unsigned offset) | |
| 282 | −{ | |
| 283 | − struct afs_operation *op = call->op; | |
| 284 | − struct page *pages[AFS_BVEC_MAX]; | |
| 285 | − unsigned int nr, n, i, to, bytes = 0; | |
| 286 | − | |
| 287 | − nr = min_t(pgoff_t, last - first + 1, AFS_BVEC_MAX); | |
| 288 | − n = find_get_pages_contig(op->store.mapping, first, nr, pages); | |
| 289 | − ASSERTCMP(n, ==, nr); | |
| 290 | − | |
| 291 | − msg->msg_flags |= MSG_MORE; | |
| 292 | − for (i = 0; i < nr; i++) { | |
| 293 | − to = PAGE_SIZE; | |
| 294 | − if (first + i >= last) { | |
| 295 | − to = op->store.last_to; | |
| 296 | − msg->msg_flags &= ~MSG_MORE; | |
| 297 | − } | |
| 298 | − bv[i].bv_page = pages[i]; | |
| 299 | − bv[i].bv_len = to - offset; | |
| 300 | − bv[i].bv_offset = offset; | |
| 301 | − bytes += to - offset; | |
| 302 | − offset = 0; | |
| 303 | − } | |
| 304 | − | |
| 305 | − iov_iter_bvec(&msg->msg_iter, WRITE, bv, nr, bytes); | |
| 306 | −} | |
| 307 | − | |
| 308 | 274 | /* |
| 309 | 275 | * Advance the AFS call state when the RxRPC call ends the transmit phase. |
| 310 | 276 | */ |
| @@ -317,42 +283,6 @@ static void afs_notify_end_request_tx(struct sock *sock, · 6 unmodified lines | ||
| 317 | 283 | afs_set_call_state(call, AFS_CALL_CL_REQUESTING, AFS_CALL_CL_AWAIT_REPLY); |
| 318 | 284 | } |
| 319 | 285 | |
| 320 | −/* | |
| 321 | − * attach the data from a bunch of pages on an inode to a call | |
| 322 | − */ | |
| 323 | −static int afs_send_pages(struct afs_call *call, struct msghdr *msg) | |
| 324 | −{ | |
| 325 | − struct afs_operation *op = call->op; | |
| 326 | − struct bio_vec bv[AFS_BVEC_MAX]; | |
| 327 | − unsigned int bytes, nr, loop, offset; | |
| 328 | − pgoff_t first = op->store.first, last = op->store.last; | |
| 329 | − int ret; | |
| 330 | − | |
| 331 | − offset = op->store.first_offset; | |
| 332 | − op->store.first_offset = 0; | |
| 333 | − | |
| 334 | − do { | |
| 335 | − afs_load_bvec(call, msg, bv, first, last, offset); | |
| 336 | − trace_afs_send_pages(call, msg, first, last, offset); | |
| 337 | − | |
| 338 | − offset = 0; | |
| 339 | − bytes = msg->msg_iter.count; | |
| 340 | − nr = msg->msg_iter.nr_segs; | |
| 341 | − | |
| 342 | − ret = rxrpc_kernel_send_data(op->net->socket, call->rxcall, msg, | |
| 343 | − bytes, afs_notify_end_request_tx); | |
| 344 | − for (loop = 0; loop < nr; loop++) | |
| 345 | − put_page(bv[loop].bv_page); | |
| 346 | − if (ret < 0) | |
| 347 | − break; | |
| 348 | − | |
| 349 | − first += nr; | |
| 350 | − } while (first <= last); | |
| 351 | − | |
| 352 | − trace_afs_sent_pages(call, op->store.first, last, first, ret); | |
| 353 | − return ret; | |
| 354 | −} | |
| 355 | − | |
| 356 | 286 | /* |
| 357 | 287 | * Initiate a call and synchronously queue up the parameters for dispatch. Any |
| 358 | 288 | * error is stored into the call struct, which the caller must check for. |
| @@ -384,21 +314,8 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp) · 25 unmodified lines | ||
| 384 | 314 | * after the initial fixed part. |
| 385 | 315 | */ |
| 386 | 316 | tx_total_len = call->request_size; |
| 387 | − if (call->send_pages) { | |
| 388 | − struct afs_operation *op = call->op; | |
| 389 | − | |
| 390 | − if (op->store.last == op->store.first) { | |
| 391 | − tx_total_len += op->store.last_to - op->store.first_offset; | |
| 392 | − } else { | |
| 393 | − /* It looks mathematically like you should be able to | |
| 394 | − * combine the following lines with the ones above, but | |
| 395 | − * unsigned arithmetic is fun when it wraps... | |
| 396 | − */ | |
| 397 | − tx_total_len += PAGE_SIZE - op->store.first_offset; | |
| 398 | − tx_total_len += op->store.last_to; | |
| 399 | − tx_total_len += (op->store.last - op->store.first - 1) * PAGE_SIZE; | |
| 400 | − } | |
| 401 | − } | |
| 317 | + if (call->write_iter) | |
| 318 | + tx_total_len += iov_iter_count(call->write_iter); | |
| 402 | 319 | |
| 403 | 320 | /* If the call is going to be asynchronous, we need an extra ref for |
| 404 | 321 | * the call to hold itself so the caller need not hang on to its ref. |
| @@ -440,7 +357,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp) · 35 unmodified lines | ||
| 440 | 357 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, call->request_size); |
| 441 | 358 | msg.msg_control = NULL; |
| 442 | 359 | msg.msg_controllen = 0; |
| 443 | − msg.msg_flags = MSG_WAITALL | (call->send_pages ? MSG_MORE : 0); | |
| 360 | + msg.msg_flags = MSG_WAITALL | (call->write_iter ? MSG_MORE : 0); | |
| 444 | 361 | |
| 445 | 362 | ret = rxrpc_kernel_send_data(call->net->socket, rxcall, |
| 446 | 363 | &msg, call->request_size, |
| @@ -448,8 +365,18 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp) · 1 unmodified line | ||
| 448 | 365 | if (ret < 0) |
| 449 | 366 | goto error_do_abort; |
| 450 | 367 | |
| 451 | − if (call->send_pages) { | |
| 452 | − ret = afs_send_pages(call, &msg); | |
| 368 | + if (call->write_iter) { | |
| 369 | + msg.msg_iter = *call->write_iter; | |
| 370 | + msg.msg_flags &= ~MSG_MORE; | |
| 371 | + trace_afs_send_data(call, &msg); | |
| 372 | + | |
| 373 | + ret = rxrpc_kernel_send_data(call->net->socket, | |
| 374 | + call->rxcall, &msg, | |
| 375 | + iov_iter_count(&msg.msg_iter), | |
| 376 | + afs_notify_end_request_tx); | |
| 377 | + *call->write_iter = msg.msg_iter; | |
| 378 | + | |
| 379 | + trace_afs_sent_data(call, &msg, ret); | |
| 453 | 380 | if (ret < 0) |
| 454 | 381 | goto error_do_abort; |
| 455 | 382 | } |
| @@ -325,36 +325,27 @@ static void afs_redirty_pages(struct writeback_control *wbc, · 324 unmodified lines | ||
| 325 | 325 | /* |
| 326 | 326 | * completion of write to server |
| 327 | 327 | */ |
| 328 | −static void afs_pages_written_back(struct afs_vnode *vnode, | |
| 329 | − pgoff_t first, pgoff_t last) | |
| 328 | +static void afs_pages_written_back(struct afs_vnode *vnode, pgoff_t start, pgoff_t last) | |
| 330 | 329 | { |
| 331 | − struct pagevec pv; | |
| 332 | − unsigned count, loop; | |
| 330 | + struct address_space *mapping = vnode->vfs_inode.i_mapping; | |
| 331 | + struct page *page; | |
| 332 | + | |
| 333 | + XA_STATE(xas, &mapping->i_pages, start); | |
| 333 | 334 | |
| 334 | 335 | _enter("{%llx:%llu},{%lx-%lx}", |
| 335 | − vnode->fid.vid, vnode->fid.vnode, first, last); | |
| 336 | + vnode->fid.vid, vnode->fid.vnode, start, last); | |
| 336 | 337 | |
| 337 | − pagevec_init(&pv); | |
| 338 | + rcu_read_lock(); | |
| 338 | 339 | |
| 339 | − do { | |
| 340 | − _debug("done %lx-%lx", first, last); | |
| 340 | + xas_for_each(&xas, page, last) { | |
| 341 | + ASSERT(PageWriteback(page)); | |
| 341 | 342 | |
| 342 | − count = last - first + 1; | |
| 343 | − if (count > PAGEVEC_SIZE) | |
| 344 | − count = PAGEVEC_SIZE; | |
| 345 | − pv.nr = find_get_pages_contig(vnode->vfs_inode.i_mapping, | |
| 346 | − first, count, pv.pages); | |
| 347 | − ASSERTCMP(pv.nr, ==, count); | |
| 343 | + detach_page_private(page); | |
| 344 | + trace_afs_page_dirty(vnode, tracepoint_string("clear"), page); | |
| 345 | + page_endio(page, true, 0); | |
| 346 | + } | |
| 348 | 347 | |
| 349 | − for (loop = 0; loop < count; loop++) { | |
| 350 | − detach_page_private(pv.pages[loop]); | |
| 351 | − trace_afs_page_dirty(vnode, tracepoint_string("clear"), | |
| 352 | − pv.pages[loop]); | |
| 353 | − end_page_writeback(pv.pages[loop]); | |
| 354 | − } | |
| 355 | − first += count; | |
| 356 | − __pagevec_release(&pv); | |
| 357 | − } while (first <= last); | |
| 348 | + rcu_read_unlock(); | |
| 358 | 349 | |
| 359 | 350 | afs_prune_wb_keys(vnode); |
| 360 | 351 | _leave(""); |
| @@ -411,9 +402,7 @@ static void afs_store_data_success(struct afs_operation *op) · 50 unmodified lines | ||
| 411 | 402 | if (!op->store.laundering) |
| 412 | 403 | afs_pages_written_back(vnode, op->store.first, op->store.last); |
| 413 | 404 | afs_stat_v(vnode, n_stores); |
| 414 | − atomic_long_add((op->store.last * PAGE_SIZE + op->store.last_to) - | |
| 415 | − (op->store.first * PAGE_SIZE + op->store.first_offset), | |
| 416 | − &afs_v2net(vnode)->n_store_bytes); | |
| 405 | + atomic_long_add(op->store.size, &afs_v2net(vnode)->n_store_bytes); | |
| 417 | 406 | } |
| 418 | 407 | } |
| 419 | 408 | |
| @@ -426,21 +415,21 @@ static const struct afs_operation_ops afs_store_data_operation = { · 6 unmodified lines | ||
| 426 | 415 | /* |
| 427 | 416 | * write to a file |
| 428 | 417 | */ |
| 429 | −static int afs_store_data(struct address_space *mapping, | |
| 430 | − pgoff_t first, pgoff_t last, | |
| 431 | − unsigned offset, unsigned to, bool laundering) | |
| 418 | +static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, | |
| 419 | + loff_t pos, pgoff_t first, pgoff_t last, | |
| 420 | + bool laundering) | |
| 432 | 421 | { |
| 433 | − struct afs_vnode *vnode = AFS_FS_I(mapping->host); | |
| 434 | 422 | struct afs_operation *op; |
| 435 | 423 | struct afs_wb_key *wbk = NULL; |
| 436 | − int ret; | |
| 424 | + loff_t size = iov_iter_count(iter), i_size; | |
| 425 | + int ret = -ENOKEY; | |
| 437 | 426 | |
| 438 | − _enter("%s{%llx:%llu.%u},%lx,%lx,%x,%x", | |
| 427 | + _enter("%s{%llx:%llu.%u},%llx,%llx", | |
| 439 | 428 | vnode->volume->name, |
| 440 | 429 | vnode->fid.vid, |
| 441 | 430 | vnode->fid.vnode, |
| 442 | 431 | vnode->fid.unique, |
| 443 | − first, last, offset, to); | |
| 432 | + size, pos); | |
| 444 | 433 | |
| 445 | 434 | ret = afs_get_writeback_key(vnode, &wbk); |
| 446 | 435 | if (ret) { |
| @@ -454,13 +443,16 @@ static int afs_store_data(struct address_space *mapping, · 7 unmodified lines | ||
| 454 | 443 | return -ENOMEM; |
| 455 | 444 | } |
| 456 | 445 | |
| 446 | + i_size = i_size_read(&vnode->vfs_inode); | |
| 447 | + | |
| 457 | 448 | afs_op_set_vnode(op, 0, vnode); |
| 458 | 449 | op->file[0].dv_delta = 1; |
| 459 | − op->store.mapping = mapping; | |
| 450 | + op->store.write_iter = iter; | |
| 451 | + op->store.pos = pos; | |
| 460 | 452 | op->store.first = first; |
| 461 | 453 | op->store.last = last; |
| 462 | − op->store.first_offset = offset; | |
| 463 | − op->store.last_to = to; | |
| 454 | + op->store.size = size; | |
| 455 | + op->store.i_size = max(pos + size, i_size); | |
| 464 | 456 | op->store.laundering = laundering; |
| 465 | 457 | op->mtime = vnode->vfs_inode.i_mtime; |
| 466 | 458 | op->flags |= AFS_OPERATION_UNINTR; |
| @@ -503,11 +495,12 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, · 36 unmodified lines | ||
| 503 | 495 | pgoff_t final_page) |
| 504 | 496 | { |
| 505 | 497 | struct afs_vnode *vnode = AFS_FS_I(mapping->host); |
| 498 | + struct iov_iter iter; | |
| 506 | 499 | struct page *pages[8], *page; |
| 507 | 500 | unsigned long count, priv; |
| 508 | 501 | unsigned n, offset, to, f, t; |
| 509 | 502 | pgoff_t start, first, last; |
| 510 | − loff_t i_size, end; | |
| 503 | + loff_t i_size, pos, end; | |
| 511 | 504 | int loop, ret; |
| 512 | 505 | |
| 513 | 506 | _enter(",%lx", primary_page->index); |
| @@ -604,15 +597,28 @@ no_more: · 90 unmodified lines | ||
| 604 | 597 | |
| 605 | 598 | first = primary_page->index; |
| 606 | 599 | last = first + count - 1; |
| 600 | + _debug("write back %lx[%u..] to %lx[..%u]", first, offset, last, to); | |
| 607 | 601 | |
| 608 | − end = (loff_t)last * PAGE_SIZE + to; | |
| 609 | − i_size = i_size_read(&vnode->vfs_inode); | |
| 602 | + pos = first; | |
| 603 | + pos <<= PAGE_SHIFT; | |
| 604 | + pos += offset; | |
| 605 | + end = last; | |
| 606 | + end <<= PAGE_SHIFT; | |
| 607 | + end += to; | |
| 610 | 608 | |
| 611 | − _debug("write back %lx[%u..] to %lx[..%u]", first, offset, last, to); | |
| 609 | + /* Trim the actual write down to the EOF */ | |
| 610 | + i_size = i_size_read(&vnode->vfs_inode); | |
| 612 | 611 | if (end > i_size) |
| 613 | − to = i_size & ~PAGE_MASK; | |
| 612 | + end = i_size; | |
| 613 | + | |
| 614 | + if (pos < i_size) { | |
| 615 | + iov_iter_xarray(&iter, WRITE, &mapping->i_pages, pos, end - pos); | |
| 616 | + ret = afs_store_data(vnode, &iter, pos, first, last, false); | |
| 617 | + } else { | |
| 618 | + /* The dirty region was entirely beyond the EOF. */ | |
| 619 | + ret = 0; | |
| 620 | + } | |
| 614 | 621 | |
| 615 | − ret = afs_store_data(mapping, first, last, offset, to, false); | |
| 616 | 622 | switch (ret) { |
| 617 | 623 | case 0: |
| 618 | 624 | ret = count; |
| @@ -912,6 +918,8 @@ int afs_launder_page(struct page *page) · 293 unmodified lines | ||
| 912 | 918 | { |
| 913 | 919 | struct address_space *mapping = page->mapping; |
| 914 | 920 | struct afs_vnode *vnode = AFS_FS_I(mapping->host); |
| 921 | + struct iov_iter iter; | |
| 922 | + struct bio_vec bv[1]; | |
| 915 | 923 | unsigned long priv; |
| 916 | 924 | unsigned int f, t; |
| 917 | 925 | int ret = 0; |
| @@ -927,8 +935,14 @@ int afs_launder_page(struct page *page) · 9 unmodified lines | ||
| 927 | 935 | t = afs_page_dirty_to(page, priv); |
| 928 | 936 | } |
| 929 | 937 | |
| 938 | + bv[0].bv_page = page; | |
| 939 | + bv[0].bv_offset = f; | |
| 940 | + bv[0].bv_len = t - f; | |
| 941 | + iov_iter_bvec(&iter, WRITE, bv, 1, bv[0].bv_len); | |
| 942 | + | |
| 930 | 943 | trace_afs_page_dirty(vnode, tracepoint_string("launder"), page); |
| 931 | − ret = afs_store_data(mapping, page->index, page->index, t, f, true); | |
| 944 | + ret = afs_store_data(vnode, &iter, (loff_t)page->index << PAGE_SHIFT, | |
| 945 | + page->index, page->index, true); | |
| 932 | 946 | } |
| 933 | 947 | |
| 934 | 948 | detach_page_private(page); |
| @@ -1078,25 +1078,15 @@ void yfs_fs_store_data(struct afs_operation *op) · 1077 unmodified lines | ||
| 1078 | 1078 | { |
| 1079 | 1079 | struct afs_vnode_param *vp = &op->file[0]; |
| 1080 | 1080 | struct afs_call *call; |
| 1081 | − loff_t size, pos, i_size; | |
| 1082 | 1081 | __be32 *bp; |
| 1083 | 1082 | |
| 1084 | 1083 | _enter(",%x,{%llx:%llu},,", |
| 1085 | 1084 | key_serial(op->key), vp->fid.vid, vp->fid.vnode); |
| 1086 | 1085 | |
| 1087 | − size = (loff_t)op->store.last_to - (loff_t)op->store.first_offset; | |
| 1088 | − if (op->store.first != op->store.last) | |
| 1089 | − size += (loff_t)(op->store.last - op->store.first) << PAGE_SHIFT; | |
| 1090 | − pos = (loff_t)op->store.first << PAGE_SHIFT; | |
| 1091 | − pos += op->store.first_offset; | |
| 1092 | − | |
| 1093 | − i_size = i_size_read(&vp->vnode->vfs_inode); | |
| 1094 | − if (pos + size > i_size) | |
| 1095 | − i_size = size + pos; | |
| 1096 | − | |
| 1097 | 1086 | _debug("size %llx, at %llx, i_size %llx", |
| 1098 | − (unsigned long long)size, (unsigned long long)pos, | |
| 1099 | − (unsigned long long)i_size); | |
| 1087 | + (unsigned long long)op->store.size, | |
| 1088 | + (unsigned long long)op->store.pos, | |
| 1089 | + (unsigned long long)op->store.i_size); | |
| 1100 | 1090 | |
| 1101 | 1091 | call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64, |
| 1102 | 1092 | sizeof(__be32) + |
| @@ -1109,8 +1099,7 @@ void yfs_fs_store_data(struct afs_operation *op) · 6 unmodified lines | ||
| 1109 | 1099 | if (!call) |
| 1110 | 1100 | return afs_op_nomem(op); |
| 1111 | 1101 | |
| 1112 | − call->key = op->key; | |
| 1113 | − call->send_pages = true; | |
| 1102 | + call->write_iter = op->store.write_iter; | |
| 1114 | 1103 | |
| 1115 | 1104 | /* marshall the parameters */ |
| 1116 | 1105 | bp = call->request; |
| @@ -1118,9 +1107,9 @@ void yfs_fs_store_data(struct afs_operation *op) · 1 unmodified line | ||
| 1118 | 1107 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ |
| 1119 | 1108 | bp = xdr_encode_YFSFid(bp, &vp->fid); |
| 1120 | 1109 | bp = xdr_encode_YFSStoreStatus_mtime(bp, &op->mtime); |
| 1121 | − bp = xdr_encode_u64(bp, pos); | |
| 1122 | − bp = xdr_encode_u64(bp, size); | |
| 1123 | − bp = xdr_encode_u64(bp, i_size); | |
| 1110 | + bp = xdr_encode_u64(bp, op->store.pos); | |
| 1111 | + bp = xdr_encode_u64(bp, op->store.size); | |
| 1112 | + bp = xdr_encode_u64(bp, op->store.i_size); | |
| 1124 | 1113 | yfs_check_req(call, bp); |
| 1125 | 1114 | |
| 1126 | 1115 | trace_afs_make_fs_call(call, &vp->fid); |
| @@ -886,65 +886,52 @@ TRACE_EVENT(afs_call_done, · 885 unmodified lines | ||
| 886 | 886 | __entry->rx_call) |
| 887 | 887 | ); |
| 888 | 888 | |
| 889 | −TRACE_EVENT(afs_send_pages, | |
| 890 | − TP_PROTO(struct afs_call *call, struct msghdr *msg, | |
| 891 | − pgoff_t first, pgoff_t last, unsigned int offset), | |
| 889 | +TRACE_EVENT(afs_send_data, | |
| 890 | + TP_PROTO(struct afs_call *call, struct msghdr *msg), | |
| 892 | 891 | |
| 893 | − TP_ARGS(call, msg, first, last, offset), | |
| 892 | + TP_ARGS(call, msg), | |
| 894 | 893 | |
| 895 | 894 | TP_STRUCT__entry( |
| 896 | 895 | __field(unsigned int, call ) |
| 897 | − __field(pgoff_t, first ) | |
| 898 | − __field(pgoff_t, last ) | |
| 899 | − __field(unsigned int, nr ) | |
| 900 | − __field(unsigned int, bytes ) | |
| 901 | − __field(unsigned int, offset ) | |
| 902 | 896 | __field(unsigned int, flags ) |
| 897 | + __field(loff_t, offset ) | |
| 898 | + __field(loff_t, count ) | |
| 903 | 899 | ), |
| 904 | 900 | |
| 905 | 901 | TP_fast_assign( |
| 906 | 902 | __entry->call = call->debug_id; |
| 907 | − __entry->first = first; | |
| 908 | − __entry->last = last; | |
| 909 | − __entry->nr = msg->msg_iter.nr_segs; | |
| 910 | − __entry->bytes = msg->msg_iter.count; | |
| 911 | − __entry->offset = offset; | |
| 912 | 903 | __entry->flags = msg->msg_flags; |
| 904 | + __entry->offset = msg->msg_iter.xarray_start + msg->msg_iter.iov_offset; | |
| 905 | + __entry->count = iov_iter_count(&msg->msg_iter); | |
| 913 | 906 | ), |
| 914 | 907 | |
| 915 | − TP_printk(" c=%08x %lx-%lx-%lx b=%x o=%x f=%x", | |
| 916 | − __entry->call, | |
| 917 | − __entry->first, __entry->first + __entry->nr - 1, __entry->last, | |
| 918 | − __entry->bytes, __entry->offset, | |
| 908 | + TP_printk(" c=%08x o=%llx n=%llx f=%x", | |
| 909 | + __entry->call, __entry->offset, __entry->count, | |
| 919 | 910 | __entry->flags) |
| 920 | 911 | ); |
| 921 | 912 | |
| 922 | −TRACE_EVENT(afs_sent_pages, | |
| 923 | − TP_PROTO(struct afs_call *call, pgoff_t first, pgoff_t last, | |
| 924 | − pgoff_t cursor, int ret), | |
| 913 | +TRACE_EVENT(afs_sent_data, | |
| 914 | + TP_PROTO(struct afs_call *call, struct msghdr *msg, int ret), | |
| 925 | 915 | |
| 926 | − TP_ARGS(call, first, last, cursor, ret), | |
| 916 | + TP_ARGS(call, msg, ret), | |
| 927 | 917 | |
| 928 | 918 | TP_STRUCT__entry( |
| 929 | 919 | __field(unsigned int, call ) |
| 930 | − __field(pgoff_t, first ) | |
| 931 | − __field(pgoff_t, last ) | |
| 932 | − __field(pgoff_t, cursor ) | |
| 933 | 920 | __field(int, ret ) |
| 921 | + __field(loff_t, offset ) | |
| 922 | + __field(loff_t, count ) | |
| 934 | 923 | ), |
| 935 | 924 | |
| 936 | 925 | TP_fast_assign( |
| 937 | 926 | __entry->call = call->debug_id; |
| 938 | − __entry->first = first; | |
| 939 | − __entry->last = last; | |
| 940 | − __entry->cursor = cursor; | |
| 941 | 927 | __entry->ret = ret; |
| 928 | + __entry->offset = msg->msg_iter.xarray_start + msg->msg_iter.iov_offset; | |
| 929 | + __entry->count = iov_iter_count(&msg->msg_iter); | |
| 942 | 930 | ), |
| 943 | 931 | |
| 944 | − TP_printk(" c=%08x %lx-%lx c=%lx r=%d", | |
| 945 | − __entry->call, | |
| 946 | − __entry->first, __entry->last, | |
| 947 | − __entry->cursor, __entry->ret) | |
| 932 | + TP_printk(" c=%08x o=%llx n=%llx r=%x", | |
| 933 | + __entry->call, __entry->offset, __entry->count, | |
| 934 | + __entry->ret) | |
| 948 | 935 | ); |
| 949 | 936 | |
| 950 | 937 | TRACE_EVENT(afs_dir_check_failed, |