|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +/* kiocb-using read/write |
| 3 | + * |
| 4 | + * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved. |
| 5 | + * Written by David Howells ([email protected]) |
| 6 | + */ |
| 7 | + |
| 8 | +#include <linux/mount.h> |
| 9 | +#include <linux/slab.h> |
| 10 | +#include <linux/file.h> |
| 11 | +#include <linux/uio.h> |
| 12 | +#include <linux/falloc.h> |
| 13 | +#include <linux/sched/mm.h> |
| 14 | +#include <trace/events/fscache.h> |
| 15 | +#include "internal.h" |
| 16 | + |
| 17 | +/* |
| 18 | + * Clean up an operation. |
| 19 | + */ |
| 20 | +static void cachefiles_end_operation(struct netfs_cache_resources *cres) |
| 21 | +{ |
| 22 | + struct file *file = cachefiles_cres_file(cres); |
| 23 | + |
| 24 | + if (file) |
| 25 | + fput(file); |
| 26 | + fscache_end_cookie_access(fscache_cres_cookie(cres), fscache_access_io_end); |
| 27 | +} |
| 28 | + |
| 29 | +static const struct netfs_cache_ops cachefiles_netfs_cache_ops = { |
| 30 | + .end_operation = cachefiles_end_operation, |
| 31 | +}; |
| 32 | + |
| 33 | +/* |
| 34 | + * Open the cache file when beginning a cache operation. |
| 35 | + */ |
| 36 | +bool cachefiles_begin_operation(struct netfs_cache_resources *cres, |
| 37 | + enum fscache_want_state want_state) |
| 38 | +{ |
| 39 | + struct cachefiles_object *object = cachefiles_cres_object(cres); |
| 40 | + |
| 41 | + if (!cachefiles_cres_file(cres)) { |
| 42 | + cres->ops = &cachefiles_netfs_cache_ops; |
| 43 | + if (object->file) { |
| 44 | + spin_lock(&object->lock); |
| 45 | + if (!cres->cache_priv2 && object->file) |
| 46 | + cres->cache_priv2 = get_file(object->file); |
| 47 | + spin_unlock(&object->lock); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + if (!cachefiles_cres_file(cres) && want_state != FSCACHE_WANT_PARAMS) { |
| 52 | + pr_err("failed to get cres->file\n"); |
| 53 | + return false; |
| 54 | + } |
| 55 | + |
| 56 | + return true; |
| 57 | +} |
0 commit comments