// SPDX-License-Identifier: GPL-2.0-or-later /* Cache data I/O routines * * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com)
*/ #define FSCACHE_DEBUG_LEVEL OPERATION #include <linux/fscache-cache.h> #include <linux/uio.h> #include <linux/bvec.h> #include <linux/slab.h> #include"internal.h"
/** * fscache_wait_for_operation - Wait for an object become accessible * @cres: The cache resources for the operation being performed * @want_state: The minimum state the object must be at * * See if the target cache object is at the specified minimum state of * accessibility yet, and if not, wait for it.
*/ bool fscache_wait_for_operation(struct netfs_cache_resources *cres, enum fscache_want_state want_state)
{ struct fscache_cookie *cookie = fscache_cres_cookie(cres); enum fscache_cookie_state state;
again: if (!fscache_cache_is_live(cookie->volume->cache)) {
_leave(" [broken]"); returnfalse;
}
state = fscache_cookie_state(cookie);
_enter("c=%08x{%u},%x", cookie->debug_id, state, want_state);
switch (state) { case FSCACHE_COOKIE_STATE_CREATING: case FSCACHE_COOKIE_STATE_INVALIDATING: if (want_state == FSCACHE_WANT_PARAMS) goto ready; /* There can be no content */
fallthrough; case FSCACHE_COOKIE_STATE_LOOKING_UP: case FSCACHE_COOKIE_STATE_LRU_DISCARDING:
wait_var_event(&cookie->state,
fscache_cookie_state(cookie) != state); goto again;
case FSCACHE_COOKIE_STATE_ACTIVE: goto ready; case FSCACHE_COOKIE_STATE_DROPPED: case FSCACHE_COOKIE_STATE_RELINQUISHING: default:
_leave(" [not live]"); returnfalse;
}
ready: if (!cres->cache_priv2) return cookie->volume->cache->ops->begin_operation(cres, want_state); returntrue;
}
EXPORT_SYMBOL(fscache_wait_for_operation);
/* * Begin an I/O operation on the cache, waiting till we reach the right state. * * Attaches the resources required to the operation resources record.
*/ staticint fscache_begin_operation(struct netfs_cache_resources *cres, struct fscache_cookie *cookie, enum fscache_want_state want_state, enum fscache_access_trace why)
{ enum fscache_cookie_state state; long timeo; bool once_only = false;
if (!fscache_begin_cookie_access(cookie, why)) {
cres->cache_priv = NULL; return -ENOBUFS;
}
again:
spin_lock(&cookie->lock);
state = fscache_cookie_state(cookie);
_enter("c=%08x{%u},%x", cookie->debug_id, state, want_state);
switch (state) { case FSCACHE_COOKIE_STATE_LOOKING_UP: case FSCACHE_COOKIE_STATE_LRU_DISCARDING: case FSCACHE_COOKIE_STATE_INVALIDATING: goto wait_for_file_wrangling; case FSCACHE_COOKIE_STATE_CREATING: if (want_state == FSCACHE_WANT_PARAMS) goto ready; /* There can be no content */ goto wait_for_file_wrangling; case FSCACHE_COOKIE_STATE_ACTIVE: goto ready; case FSCACHE_COOKIE_STATE_DROPPED: case FSCACHE_COOKIE_STATE_RELINQUISHING:
WARN(1, "Can't use cookie in state %u\n", cookie->state); goto not_live; default: goto not_live;
}
ready:
spin_unlock(&cookie->lock); if (!cookie->volume->cache->ops->begin_operation(cres, want_state)) goto failed; return 0;
/* * Deal with the completion of writing the data to the cache.
*/ staticvoid fscache_wreq_done(void *priv, ssize_t transferred_or_error)
{ struct fscache_write_request *wreq = priv;
if (wreq->using_pgpriv2)
fscache_clear_page_bits(wreq->mapping, wreq->start, wreq->len,
wreq->set_bits);
if (wreq->term_func)
wreq->term_func(wreq->term_func_priv, transferred_or_error);
fscache_end_operation(&wreq->cache_resources);
kfree(wreq);
}
ret = cres->ops->prepare_write(cres, &start, &len, len, i_size, false); if (ret < 0) goto abandon_end;
/* TODO: Consider clearing page bits now for space the write isn't * covering. This is more complicated than it appears when THPs are * taken into account.
*/
/* We cannot defer a resize as we need to do it inside the * netfs's inode lock so that we're serialised with respect to * writes.
*/
cookie->volume->cache->ops->resize_cookie(&cres, new_size);
fscache_end_operation(&cres);
} else {
fscache_stat(&fscache_n_resizes_null);
}
}
EXPORT_SYMBOL(__fscache_resize_cookie);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.