| 1 | |
| 2 | |
| 3 | *
|
| 4 | * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
|
| 5 | * Written by David Howells ([email protected])
|
| 6 |
|
| 7 |
|
| 8 | #include <linux/kernel.h>
|
| 9 | #include <linux/module.h>
|
| 10 | #include <linux/init.h>
|
| 11 | #include <linux/fs.h>
|
| 12 | #include <linux/pagemap.h>
|
| 13 | #include <linux/writeback.h>
|
| 14 | #include <linux/gfp.h>
|
| 15 | #include <linux/task_io_accounting_ops.h>
|
| 16 | #include <linux/mm.h>
|
| 17 | #include <linux/swap.h>
|
| 18 | #include <linux/netfs.h>
|
| 19 | #include <trace/events/netfs.h>
|
| 20 | #include "internal.h"
|
| 21 |
|
| 22 | static int afs_file_mmap_prepare(struct vm_area_desc *desc);
|
| 23 |
|
| 24 | static ssize_t afs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter);
|
| 25 | static ssize_t afs_file_splice_read(struct file *in, loff_t *ppos,
|
| 26 | struct pipe_inode_info *pipe,
|
| 27 | size_t len, unsigned int flags);
|
| 28 | static void afs_vm_open(struct vm_area_struct *area);
|
| 29 | static void afs_vm_close(struct vm_area_struct *area);
|
| 30 | static vm_fault_t afs_vm_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff);
|
| 31 | static int afs_mapped(unsigned long start, unsigned long end, pgoff_t pgoff,
|
| 32 | const struct file *file, void **vm_private_data);
|
| 33 |
|
| 34 | const struct file_operations afs_file_operations = {
|
| 35 | .open = afs_open,
|
| 36 | .release = afs_release,
|
| 37 | .llseek = generic_file_llseek,
|
| 38 | .read_iter = afs_file_read_iter,
|
| 39 | .write_iter = netfs_file_write_iter,
|
| 40 | .mmap_prepare = afs_file_mmap_prepare,
|
| 41 | .splice_read = afs_file_splice_read,
|
| 42 | .splice_write = iter_file_splice_write,
|
| 43 | .fsync = afs_fsync,
|
| 44 | .lock = afs_lock,
|
| 45 | .flock = afs_flock,
|
| 46 | };
|
| 47 |
|
| 48 | const struct inode_operations afs_file_inode_operations = {
|
| 49 | .getattr = afs_getattr,
|
| 50 | .setattr = afs_setattr,
|
| 51 | .permission = afs_permission,
|
| 52 | };
|
| 53 |
|
| 54 | const struct address_space_operations afs_file_aops = {
|
| 55 | .direct_IO = noop_direct_IO,
|
| 56 | .read_folio = netfs_read_folio,
|
| 57 | .readahead = netfs_readahead,
|
| 58 | .dirty_folio = netfs_dirty_folio,
|
| 59 | .release_folio = netfs_release_folio,
|
| 60 | .invalidate_folio = netfs_invalidate_folio,
|
| 61 | .migrate_folio = filemap_migrate_folio,
|
| 62 | .writepages = afs_writepages,
|
| 63 | };
|
| 64 |
|
| 65 | static const struct vm_operations_struct afs_vm_ops = {
|
| 66 | .mapped = afs_mapped,
|
| 67 | .open = afs_vm_open,
|
| 68 | .close = afs_vm_close,
|
| 69 | .fault = filemap_fault,
|
| 70 | .map_pages = afs_vm_map_pages,
|
| 71 | .page_mkwrite = afs_page_mkwrite,
|
| 72 | };
|
| 73 |
|
| 74 | |
| 75 | * Discard a pin on a writeback key.
|
| 76 |
|
| 77 | void afs_put_wb_key(struct afs_wb_key *wbk)
|
| 78 | {
|
| 79 | if (wbk && refcount_dec_and_test(&wbk->usage)) {
|
| 80 | key_put(wbk->key);
|
| 81 | kfree(wbk);
|
| 82 | }
|
| 83 | }
|
| 84 |
|
| 85 | |
| 86 | * Cache key for writeback.
|
| 87 |
|
| 88 | int afs_cache_wb_key(struct afs_vnode *vnode, struct afs_file *af)
|
| 89 | {
|
| 90 | struct afs_wb_key *wbk, *p;
|
| 91 |
|
| 92 | wbk = kzalloc_obj(struct afs_wb_key);
|
| 93 | if (!wbk)
|
| 94 | return -ENOMEM;
|
| 95 | refcount_set(&wbk->usage, 2);
|
| 96 | wbk->key = af->key;
|
| 97 |
|
| 98 | spin_lock(&vnode->wb_lock);
|
| 99 | list_for_each_entry(p, &vnode->wb_keys, vnode_link) {
|
| 100 | if (p->key == wbk->key)
|
| 101 | goto found;
|
| 102 | }
|
| 103 |
|
| 104 | key_get(wbk->key);
|
| 105 | list_add_tail(&wbk->vnode_link, &vnode->wb_keys);
|
| 106 | spin_unlock(&vnode->wb_lock);
|
| 107 | af->wb = wbk;
|
| 108 | return 0;
|
| 109 |
|
| 110 | found:
|
| 111 | refcount_inc(&p->usage);
|
| 112 | spin_unlock(&vnode->wb_lock);
|
| 113 | af->wb = p;
|
| 114 | kfree(wbk);
|
| 115 | return 0;
|
| 116 | }
|
| 117 |
|
| 118 | |
| 119 | * open an AFS file or directory and attach a key to it
|
| 120 |
|
| 121 | int afs_open(struct inode *inode, struct file *file)
|
| 122 | {
|
| 123 | struct afs_vnode *vnode = AFS_FS_I(inode);
|
| 124 | struct afs_file *af;
|
| 125 | struct key *key;
|
| 126 | int ret;
|
| 127 |
|
| 128 | _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode);
|
| 129 |
|
| 130 | key = afs_request_key(vnode->volume->cell);
|
| 131 | if (IS_ERR(key)) {
|
| 132 | ret = PTR_ERR(key);
|
| 133 | goto error;
|
| 134 | }
|
| 135 |
|
| 136 | af = kzalloc_obj(*af);
|
| 137 | if (!af) {
|
| 138 | ret = -ENOMEM;
|
| 139 | goto error_key;
|
| 140 | }
|
| 141 | af->key = key;
|
| 142 |
|
| 143 | ret = afs_validate(vnode, key);
|
| 144 | if (ret < 0)
|
| 145 | goto error_af;
|
| 146 |
|
| 147 | if (file->f_mode & FMODE_WRITE) {
|
| 148 | ret = afs_cache_wb_key(vnode, af);
|
| 149 | if (ret < 0)
|
| 150 | goto error_af;
|
| 151 | }
|
| 152 |
|
| 153 | if (file->f_flags & O_TRUNC)
|
| 154 | set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
|
| 155 |
|
| 156 | fscache_use_cookie(afs_vnode_cache(vnode), file->f_mode & FMODE_WRITE);
|
| 157 |
|
| 158 | file->private_data = af;
|
| 159 | _leave(" = 0");
|
| 160 | return 0;
|
| 161 |
|
| 162 | error_af:
|
| 163 | kfree(af);
|
| 164 | error_key:
|
| 165 | key_put(key);
|
| 166 | error:
|
| 167 | _leave(" = %d", ret);
|
| 168 | return ret;
|
| 169 | }
|
| 170 |
|
| 171 | |
| 172 | * release an AFS file or directory and discard its key
|
| 173 |
|
| 174 | int afs_release(struct inode *inode, struct file *file)
|
| 175 | {
|
| 176 | struct afs_vnode_cache_aux aux;
|
| 177 | struct afs_vnode *vnode = AFS_FS_I(inode);
|
| 178 | struct afs_file *af = file->private_data;
|
| 179 | loff_t i_size;
|
| 180 | int ret = 0;
|
| 181 |
|
| 182 | _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode);
|
| 183 |
|
| 184 | if ((file->f_mode & FMODE_WRITE))
|
| 185 | ret = vfs_fsync(file, 0);
|
| 186 |
|
| 187 | file->private_data = NULL;
|
| 188 | if (af->wb)
|
| 189 | afs_put_wb_key(af->wb);
|
| 190 |
|
| 191 | if ((file->f_mode & FMODE_WRITE)) {
|
| 192 | i_size = i_size_read(&vnode->netfs.inode);
|
| 193 | afs_set_cache_aux(vnode, &aux);
|
| 194 | fscache_unuse_cookie(afs_vnode_cache(vnode), &aux, &i_size);
|
| 195 | } else {
|
| 196 | fscache_unuse_cookie(afs_vnode_cache(vnode), NULL, NULL);
|
| 197 | }
|
| 198 |
|
| 199 | key_put(af->key);
|
| 200 | kfree(af);
|
| 201 | afs_prune_wb_keys(vnode);
|
| 202 | _leave(" = %d", ret);
|
| 203 | return ret;
|
| 204 | }
|
| 205 |
|
| 206 | static void afs_fetch_data_notify(struct afs_operation *op)
|
| 207 | {
|
| 208 | struct netfs_io_subrequest *subreq = op->fetch.subreq;
|
| 209 |
|
| 210 | subreq->error = afs_op_error(op);
|
| 211 | netfs_read_subreq_terminated(subreq);
|
| 212 | }
|
| 213 |
|
| 214 | static void afs_fetch_data_success(struct afs_operation *op)
|
| 215 | {
|
| 216 | struct afs_vnode *vnode = op->file[0].vnode;
|
| 217 |
|
| 218 | _enter("op=%08x", op->debug_id);
|
| 219 | afs_vnode_commit_status(op, &op->file[0]);
|
| 220 | afs_stat_v(vnode, n_fetches);
|
| 221 | atomic_long_add(op->fetch.subreq->transferred, &op->net->n_fetch_bytes);
|
| 222 | afs_fetch_data_notify(op);
|
| 223 | }
|
| 224 |
|
| 225 | static void afs_fetch_data_aborted(struct afs_operation *op)
|
| 226 | {
|
| 227 | afs_check_for_remote_deletion(op);
|
| 228 | afs_fetch_data_notify(op);
|
| 229 | }
|
| 230 |
|
| 231 | const struct afs_operation_ops afs_fetch_data_operation = {
|
| 232 | .issue_afs_rpc = afs_fs_fetch_data,
|
| 233 | .issue_yfs_rpc = yfs_fs_fetch_data,
|
| 234 | .success = afs_fetch_data_success,
|
| 235 | .aborted = afs_fetch_data_aborted,
|
| 236 | .failed = afs_fetch_data_notify,
|
| 237 | };
|
| 238 |
|
| 239 | static void afs_issue_read_call(struct afs_operation *op)
|
| 240 | {
|
| 241 | op->call_responded = false;
|
| 242 | op->call_error = 0;
|
| 243 | op->call_abort_code = 0;
|
| 244 | if (test_bit(AFS_SERVER_FL_IS_YFS, &op->server->flags))
|
| 245 | yfs_fs_fetch_data(op);
|
| 246 | else
|
| 247 | afs_fs_fetch_data(op);
|
| 248 | }
|
| 249 |
|
| 250 | static void afs_end_read(struct afs_operation *op)
|
| 251 | {
|
| 252 | if (op->call_responded && op->server)
|
| 253 | set_bit(AFS_SERVER_FL_RESPONDING, &op->server->flags);
|
| 254 |
|
| 255 | if (!afs_op_error(op))
|
| 256 | afs_fetch_data_success(op);
|
| 257 | else if (op->cumul_error.aborted)
|
| 258 | afs_fetch_data_aborted(op);
|
| 259 | else
|
| 260 | afs_fetch_data_notify(op);
|
| 261 |
|
| 262 | afs_end_vnode_operation(op);
|
| 263 | afs_put_operation(op);
|
| 264 | }
|
| 265 |
|
| 266 | |
| 267 | * Perform I/O processing on an asynchronous call. The work item carries a ref
|
| 268 | * to the call struct that we either need to release or to pass on.
|
| 269 |
|
| 270 | static void afs_read_receive(struct afs_call *call)
|
| 271 | {
|
| 272 | struct afs_operation *op = call->op;
|
| 273 | enum afs_call_state state;
|
| 274 |
|
| 275 | _enter("");
|
| 276 |
|
| 277 | state = READ_ONCE(call->state);
|
| 278 | if (state == AFS_CALL_COMPLETE)
|
| 279 | return;
|
| 280 | trace_afs_read_recv(op, call);
|
| 281 |
|
| 282 | while (state < AFS_CALL_COMPLETE && READ_ONCE(call->need_attention)) {
|
| 283 | WRITE_ONCE(call->need_attention, false);
|
| 284 | afs_deliver_to_call(call);
|
| 285 | state = READ_ONCE(call->state);
|
| 286 | }
|
| 287 |
|
| 288 | if (state < AFS_CALL_COMPLETE) {
|
| 289 | netfs_read_subreq_progress(op->fetch.subreq);
|
| 290 | if (rxrpc_kernel_check_life(call->net->socket, call->rxcall))
|
| 291 | return;
|
| 292 |
|
| 293 | afs_set_call_complete(call, call->error, call->abort_code);
|
| 294 | }
|
| 295 |
|
| 296 | op->call_abort_code = call->abort_code;
|
| 297 | op->call_error = call->error;
|
| 298 | op->call_responded = call->responded;
|
| 299 | op->call = NULL;
|
| 300 | call->op = NULL;
|
| 301 | afs_put_call(call);
|
| 302 |
|
| 303 | |
| 304 | * handle and try the next.
|
| 305 |
|
| 306 | if (afs_select_fileserver(op)) {
|
| 307 | afs_issue_read_call(op);
|
| 308 | return;
|
| 309 | }
|
| 310 |
|
| 311 | afs_end_read(op);
|
| 312 | }
|
| 313 |
|
| 314 | void afs_fetch_data_async_rx(struct work_struct *work)
|
| 315 | {
|
| 316 | struct afs_call *call = container_of(work, struct afs_call, async_work);
|
| 317 |
|
| 318 | afs_read_receive(call);
|
| 319 | afs_put_call(call);
|
| 320 | }
|
| 321 |
|
| 322 | void afs_fetch_data_immediate_cancel(struct afs_call *call)
|
| 323 | {
|
| 324 | if (call->async) {
|
| 325 | afs_get_call(call, afs_call_trace_wake);
|
| 326 | if (!queue_work(afs_async_calls, &call->async_work))
|
| 327 | afs_deferred_put_call(call);
|
| 328 | flush_work(&call->async_work);
|
| 329 | }
|
| 330 | }
|
| 331 |
|
| 332 | |
| 333 | * Fetch file data from the volume.
|
| 334 |
|
| 335 | static void afs_issue_read(struct netfs_io_subrequest *subreq)
|
| 336 | {
|
| 337 | struct afs_operation *op;
|
| 338 | struct afs_vnode *vnode = AFS_FS_I(subreq->rreq->inode);
|
| 339 | struct key *key = subreq->rreq->netfs_priv;
|
| 340 |
|
| 341 | _enter("%s{%llx:%llu.%u},%x,,,",
|
| 342 | vnode->volume->name,
|
| 343 | vnode->fid.vid,
|
| 344 | vnode->fid.vnode,
|
| 345 | vnode->fid.unique,
|
| 346 | key_serial(key));
|
| 347 |
|
| 348 | op = afs_alloc_operation(key, vnode->volume);
|
| 349 | if (IS_ERR(op)) {
|
| 350 | subreq->error = PTR_ERR(op);
|
| 351 | netfs_read_subreq_terminated(subreq);
|
| 352 | return;
|
| 353 | }
|
| 354 |
|
| 355 | afs_op_set_vnode(op, 0, vnode);
|
| 356 |
|
| 357 | op->fetch.subreq = subreq;
|
| 358 | op->ops = &afs_fetch_data_operation;
|
| 359 |
|
| 360 | trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
|
| 361 |
|
| 362 | if (subreq->rreq->origin == NETFS_READAHEAD ||
|
| 363 | subreq->rreq->iocb) {
|
| 364 | op->flags |= AFS_OPERATION_ASYNC;
|
| 365 |
|
| 366 | if (!afs_begin_vnode_operation(op)) {
|
| 367 | subreq->error = afs_put_operation(op);
|
| 368 | netfs_read_subreq_terminated(subreq);
|
| 369 | return;
|
| 370 | }
|
| 371 |
|
| 372 | if (!afs_select_fileserver(op)) {
|
| 373 | afs_end_read(op);
|
| 374 | return;
|
| 375 | }
|
| 376 |
|
| 377 | afs_issue_read_call(op);
|
| 378 | } else {
|
| 379 | afs_do_sync_operation(op);
|
| 380 | }
|
| 381 | }
|
| 382 |
|
| 383 | static int afs_init_request(struct netfs_io_request *rreq, struct file *file)
|
| 384 | {
|
| 385 | struct afs_vnode *vnode = AFS_FS_I(rreq->inode);
|
| 386 |
|
| 387 | if (file)
|
| 388 | rreq->netfs_priv = key_get(afs_file_key(file));
|
| 389 | rreq->rsize = 256 * 1024;
|
| 390 | rreq->wsize = 256 * 1024 * 1024;
|
| 391 |
|
| 392 | switch (rreq->origin) {
|
| 393 | case NETFS_READ_SINGLE:
|
| 394 | if (!file) {
|
| 395 | struct key *key = afs_request_key(vnode->volume->cell);
|
| 396 |
|
| 397 | if (IS_ERR(key))
|
| 398 | return PTR_ERR(key);
|
| 399 | rreq->netfs_priv = key;
|
| 400 | }
|
| 401 | break;
|
| 402 | case NETFS_WRITEBACK:
|
| 403 | case NETFS_UNBUFFERED_WRITE:
|
| 404 | case NETFS_DIO_WRITE:
|
| 405 | if (S_ISREG(rreq->inode->i_mode))
|
| 406 | rreq->io_streams[0].avail = true;
|
| 407 | break;
|
| 408 | case NETFS_WRITEBACK_SINGLE:
|
| 409 | default:
|
| 410 | break;
|
| 411 | }
|
| 412 | return 0;
|
| 413 | }
|
| 414 |
|
| 415 | static int afs_check_write_begin(struct file *file, uoff_t pos, unsigned len,
|
| 416 | struct folio **foliop, void **_fsdata)
|
| 417 | {
|
| 418 | struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
|
| 419 |
|
| 420 | return test_bit(AFS_VNODE_DELETED, &vnode->flags) ? -ESTALE : 0;
|
| 421 | }
|
| 422 |
|
| 423 | static void afs_free_request(struct netfs_io_request *rreq)
|
| 424 | {
|
| 425 | key_put(rreq->netfs_priv);
|
| 426 | afs_put_wb_key(rreq->netfs_priv2);
|
| 427 | }
|
| 428 |
|
| 429 | |
| 430 | * Set the file size and block count, taking ->cb_lock and ->i_lock to maintain
|
| 431 | * coherency and prevent 64-bit tearing on 32-bit arches.
|
| 432 | *
|
| 433 | * Also, estimate the number of 512 bytes blocks used, rounded up to nearest 1K
|
| 434 | * for consistency with other AFS clients.
|
| 435 |
|
| 436 | void afs_set_i_size(struct afs_vnode *vnode, uoff_t new_i_size)
|
| 437 | {
|
| 438 | struct inode *inode = &vnode->netfs.inode;
|
| 439 | loff_t i_size;
|
| 440 |
|
| 441 | write_seqlock(&vnode->cb_lock);
|
| 442 | spin_lock(&inode->i_lock);
|
| 443 | i_size = i_size_read(inode);
|
| 444 | if (new_i_size > i_size) {
|
| 445 | i_size_write(inode, new_i_size);
|
| 446 | inode_set_bytes(inode, round_up(new_i_size, 1024));
|
| 447 | }
|
| 448 | spin_unlock(&inode->i_lock);
|
| 449 | write_sequnlock(&vnode->cb_lock);
|
| 450 | }
|
| 451 |
|
| 452 | static void afs_update_i_size(struct inode *inode, uoff_t new_i_size)
|
| 453 | {
|
| 454 | afs_set_i_size(AFS_FS_I(inode), new_i_size);
|
| 455 | }
|
| 456 |
|
| 457 | static void afs_netfs_invalidate_cache(struct netfs_io_request *wreq)
|
| 458 | {
|
| 459 | struct afs_vnode *vnode = AFS_FS_I(wreq->inode);
|
| 460 |
|
| 461 | afs_invalidate_cache(vnode, 0);
|
| 462 | }
|
| 463 |
|
| 464 | const struct netfs_request_ops afs_req_ops = {
|
| 465 | .init_request = afs_init_request,
|
| 466 | .free_request = afs_free_request,
|
| 467 | .check_write_begin = afs_check_write_begin,
|
| 468 | .issue_read = afs_issue_read,
|
| 469 | .update_i_size = afs_update_i_size,
|
| 470 | .invalidate_cache = afs_netfs_invalidate_cache,
|
| 471 | .begin_writeback = afs_begin_writeback,
|
| 472 | .prepare_write = afs_prepare_write,
|
| 473 | .issue_write = afs_issue_write,
|
| 474 | .retry_request = afs_retry_request,
|
| 475 | };
|
| 476 |
|
| 477 | static void afs_add_open_mmap(struct afs_vnode *vnode)
|
| 478 | {
|
| 479 | if (atomic_inc_return(&vnode->cb_nr_mmap) == 1) {
|
| 480 | down_write(&vnode->volume->open_mmaps_lock);
|
| 481 |
|
| 482 | if (list_empty(&vnode->cb_mmap_link))
|
| 483 | list_add_tail(&vnode->cb_mmap_link, &vnode->volume->open_mmaps);
|
| 484 |
|
| 485 | up_write(&vnode->volume->open_mmaps_lock);
|
| 486 | }
|
| 487 | }
|
| 488 |
|
| 489 | static void afs_drop_open_mmap(struct afs_vnode *vnode)
|
| 490 | {
|
| 491 | if (atomic_add_unless(&vnode->cb_nr_mmap, -1, 1))
|
| 492 | return;
|
| 493 |
|
| 494 | down_write(&vnode->volume->open_mmaps_lock);
|
| 495 |
|
| 496 | read_seqlock_excl(&vnode->cb_lock);
|
| 497 | |
| 498 | |
| 499 | if (atomic_dec_and_test(&vnode->cb_nr_mmap))
|
| 500 | list_del_init(&vnode->cb_mmap_link);
|
| 501 | read_sequnlock_excl(&vnode->cb_lock);
|
| 502 |
|
| 503 | up_write(&vnode->volume->open_mmaps_lock);
|
| 504 | flush_work(&vnode->cb_work);
|
| 505 | }
|
| 506 |
|
| 507 | |
| 508 | * Handle setting up a memory mapping on an AFS file.
|
| 509 |
|
| 510 | static int afs_file_mmap_prepare(struct vm_area_desc *desc)
|
| 511 | {
|
| 512 | int ret;
|
| 513 |
|
| 514 | ret = generic_file_mmap_prepare(desc);
|
| 515 | if (ret)
|
| 516 | return ret;
|
| 517 |
|
| 518 | desc->vm_ops = &afs_vm_ops;
|
| 519 | return ret;
|
| 520 | }
|
| 521 |
|
| 522 | static int afs_mapped(unsigned long start, unsigned long end, pgoff_t pgoff,
|
| 523 | const struct file *file, void **vm_private_data)
|
| 524 | {
|
| 525 | struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
|
| 526 |
|
| 527 | afs_add_open_mmap(vnode);
|
| 528 | return 0;
|
| 529 | }
|
| 530 |
|
| 531 | static void afs_vm_open(struct vm_area_struct *vma)
|
| 532 | {
|
| 533 | struct file *file = vma->vm_file;
|
| 534 | struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
|
| 535 |
|
| 536 | afs_add_open_mmap(vnode);
|
| 537 | }
|
| 538 |
|
| 539 | static void afs_vm_close(struct vm_area_struct *vma)
|
| 540 | {
|
| 541 | struct file *file = vma->vm_file;
|
| 542 | struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
|
| 543 |
|
| 544 | afs_drop_open_mmap(vnode);
|
| 545 | }
|
| 546 |
|
| 547 | static vm_fault_t afs_vm_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff)
|
| 548 | {
|
| 549 | struct file *file = vmf->vma->vm_file;
|
| 550 | struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
|
| 551 |
|
| 552 | if (afs_check_validity(vnode))
|
| 553 | return filemap_map_pages(vmf, start_pgoff, end_pgoff);
|
| 554 | return 0;
|
| 555 | }
|
| 556 |
|
| 557 | static ssize_t afs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
|
| 558 | {
|
| 559 | struct inode *inode = file_inode(iocb->ki_filp);
|
| 560 | struct afs_vnode *vnode = AFS_FS_I(inode);
|
| 561 | struct afs_file *af = iocb->ki_filp->private_data;
|
| 562 | ssize_t ret;
|
| 563 |
|
| 564 | if (iocb->ki_flags & IOCB_DIRECT)
|
| 565 | return netfs_unbuffered_read_iter(iocb, iter);
|
| 566 |
|
| 567 | ret = netfs_start_io_read(inode);
|
| 568 | if (ret < 0)
|
| 569 | return ret;
|
| 570 | ret = afs_validate(vnode, af->key);
|
| 571 | if (ret == 0)
|
| 572 | ret = filemap_read(iocb, iter, 0);
|
| 573 | netfs_end_io_read(inode);
|
| 574 | return ret;
|
| 575 | }
|
| 576 |
|
| 577 | static ssize_t afs_file_splice_read(struct file *in, loff_t *ppos,
|
| 578 | struct pipe_inode_info *pipe,
|
| 579 | size_t len, unsigned int flags)
|
| 580 | {
|
| 581 | struct inode *inode = file_inode(in);
|
| 582 | struct afs_vnode *vnode = AFS_FS_I(inode);
|
| 583 | struct afs_file *af = in->private_data;
|
| 584 | ssize_t ret;
|
| 585 |
|
| 586 | ret = netfs_start_io_read(inode);
|
| 587 | if (ret < 0)
|
| 588 | return ret;
|
| 589 | ret = afs_validate(vnode, af->key);
|
| 590 | if (ret == 0)
|
| 591 | ret = filemap_splice_read(in, ppos, pipe, len, flags);
|
| 592 | netfs_end_io_read(inode);
|
| 593 | return ret;
|
| 594 | }
|