Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62f8e6c5 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'fscache-next-20180406' of...

Merge tag 'fscache-next-20180406' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs

Pull fscache updates from David Howells:
 "Three patches that fix some of AFS's usage of fscache:

   (1) Need to invalidate the cache if a foreign data change is detected
       on the server.

   (2) Move the vnode ID uniquifier (equivalent to i_generation) from
       the auxiliary data to the index key to prevent a race between
       file delete and a subsequent file create seeing the same index
       key.

   (3) Need to retire cookies that correspond to files that we think got
       deleted on the server.

  Four patches to fix some things in fscache and cachefiles:

   (4) Fix a couple of checker warnings.

   (5) Correctly indicate to the end-of-operation callback whether an
       operation completed or was cancelled.

   (6) Add a check for multiple cookie relinquishment.

   (7) Fix a path through the asynchronous write that doesn't wake up a
       waiter for a page if the cache decides not to write that page,
       but discards it instead.

  A couple of patches to add tracepoints to fscache and cachefiles:

   (8) Add tracepoints for cookie operators, object state machine
       execution, cachefiles object management and cachefiles VFS
       operations.

   (9) Add tracepoints for fscache operation management and page
       wrangling.

  And then three development patches:

  (10) Attach the index key and auxiliary data to the cookie, pass this
       information through various fscache-netfs API functions and get
       rid of the callbacks to the netfs to get it.

       This means that the cache can get at this information, even if
       the netfs goes away. It also means that the cache can be lazy in
       updating the coherency data.

  (11) Pass the object data size through various fscache-netfs API
       rather than calling back to the netfs for it, and store the value
       in the object.

       This makes it easier to correctly resize the object, as the size
       is updated on writes to the cache, rather than calling back out
       to the netfs.

  (12) Maintain a catalogue of allocated cookies. This makes it possible
       to catch cookie collision up front rather than down in the bowels
       of the cache being run from a service thread from the object
       state machine.

       This will also make it possible in the future to reconnect to a
       cookie that's not gone dead yet because it's waiting for
       finalisation of the storage and also make it possible to bring
       cookies online if the cache is added after the cookie has been
       obtained"

* tag 'fscache-next-20180406' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs:
  fscache: Maintain a catalogue of allocated cookies
  fscache: Pass object size in rather than calling back for it
  fscache: Attach the index key and aux data to the cookie
  fscache: Add more tracepoints
  fscache: Add tracepoints
  fscache: Fix hanging wait on page discarded by writeback
  fscache: Detect multiple relinquishment of a cookie
  fscache: Pass the correct cancelled indications to fscache_op_complete()
  fscache, cachefiles: Fix checker warnings
  afs: Be more aggressive in retiring cached vnodes
  afs: Use the vnode ID uniquifier in the cache key not the aux data
  afs: Invalidate cache on server data change
parents f605ba97 ec0328e4
Loading
Loading
Loading
Loading
+77 −80
Original line number Original line Diff line number Diff line
@@ -129,20 +129,10 @@ To define an object, a structure of the following type should be filled out:
			const void *parent_netfs_data,
			const void *parent_netfs_data,
			const void *cookie_netfs_data);
			const void *cookie_netfs_data);


		uint16_t (*get_key)(const void *cookie_netfs_data,
				    void *buffer,
				    uint16_t bufmax);

		void (*get_attr)(const void *cookie_netfs_data,
				 uint64_t *size);

		uint16_t (*get_aux)(const void *cookie_netfs_data,
				    void *buffer,
				    uint16_t bufmax);

		enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
		enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
						   const void *data,
						   const void *data,
						   uint16_t datalen);
						   uint16_t datalen,
						   loff_t object_size);


		void (*get_context)(void *cookie_netfs_data, void *context);
		void (*get_context)(void *cookie_netfs_data, void *context);


@@ -187,36 +177,7 @@ This has the following fields:
     cache in the parent's list will be chosen, or failing that, the first
     cache in the parent's list will be chosen, or failing that, the first
     cache in the master list.
     cache in the master list.


 (4) A function to retrieve an object's key from the netfs [mandatory].
 (4) A function to check the auxiliary data [optional].

     This function will be called with the netfs data that was passed to the
     cookie acquisition function and the maximum length of key data that it may
     provide.  It should write the required key data into the given buffer and
     return the quantity it wrote.

 (5) A function to retrieve attribute data from the netfs [optional].

     This function will be called with the netfs data that was passed to the
     cookie acquisition function.  It should return the size of the file if
     this is a data file.  The size may be used to govern how much cache must
     be reserved for this file in the cache.

     If the function is absent, a file size of 0 is assumed.

 (6) A function to retrieve auxiliary data from the netfs [optional].

     This function will be called with the netfs data that was passed to the
     cookie acquisition function and the maximum length of auxiliary data that
     it may provide.  It should write the auxiliary data into the given buffer
     and return the quantity it wrote.

     If this function is absent, the auxiliary data length will be set to 0.

     The length of the auxiliary data buffer may be dependent on the key
     length.  A netfs mustn't rely on being able to provide more than 400 bytes
     for both.

 (7) A function to check the auxiliary data [optional].


     This function will be called to check that a match found in the cache for
     This function will be called to check that a match found in the cache for
     this object is valid.  For instance with AFS it could check the auxiliary
     this object is valid.  For instance with AFS it could check the auxiliary
@@ -226,6 +187,9 @@ This has the following fields:
     If this function is absent, it will be assumed that matching objects in a
     If this function is absent, it will be assumed that matching objects in a
     cache are always valid.
     cache are always valid.


     The function is also passed the cache's idea of the object size and may
     use this to manage coherency also.

     If present, the function should return one of the following values:
     If present, the function should return one of the following values:


	(*) FSCACHE_CHECKAUX_OKAY		- the entry is okay as is
	(*) FSCACHE_CHECKAUX_OKAY		- the entry is okay as is
@@ -235,7 +199,7 @@ This has the following fields:
     This function can also be used to extract data from the auxiliary data in
     This function can also be used to extract data from the auxiliary data in
     the cache and copy it into the netfs's structures.
     the cache and copy it into the netfs's structures.


 (8) A pair of functions to manage contexts for the completion callback
 (5) A pair of functions to manage contexts for the completion callback
     [optional].
     [optional].


     The cache read/write functions are passed a context which is then passed
     The cache read/write functions are passed a context which is then passed
@@ -249,7 +213,7 @@ This has the following fields:
     required for indices as indices may not contain data.  These functions may
     required for indices as indices may not contain data.  These functions may
     be called in interrupt context and so may not sleep.
     be called in interrupt context and so may not sleep.


 (9) A function to mark a page as retaining cache metadata [optional].
 (6) A function to mark a page as retaining cache metadata [optional].


     This is called by the cache to indicate that it is retaining in-memory
     This is called by the cache to indicate that it is retaining in-memory
     information for this page and that the netfs should uncache the page when
     information for this page and that the netfs should uncache the page when
@@ -261,7 +225,7 @@ This has the following fields:


     This function is not required for indices as they're not permitted data.
     This function is not required for indices as they're not permitted data.


(10) A function to unmark all the pages retaining cache metadata [mandatory].
 (7) A function to unmark all the pages retaining cache metadata [mandatory].


     This is called by FS-Cache to indicate that a backing store is being
     This is called by FS-Cache to indicate that a backing store is being
     unbound from a cookie and that all the marks on the pages should be
     unbound from a cookie and that all the marks on the pages should be
@@ -333,12 +297,32 @@ the path to the file:
	struct fscache_cookie *
	struct fscache_cookie *
	fscache_acquire_cookie(struct fscache_cookie *parent,
	fscache_acquire_cookie(struct fscache_cookie *parent,
			       const struct fscache_object_def *def,
			       const struct fscache_object_def *def,
			       const void *index_key,
			       size_t index_key_len,
			       const void *aux_data,
			       size_t aux_data_len,
			       void *netfs_data,
			       void *netfs_data,
			       loff_t object_size,
			       bool enable);
			       bool enable);


This function creates an index entry in the index represented by parent,
This function creates an index entry in the index represented by parent,
filling in the index entry by calling the operations pointed to by def.
filling in the index entry by calling the operations pointed to by def.


A unique key that represents the object within the parent must be pointed to by
index_key and is of length index_key_len.

An optional blob of auxiliary data that is to be stored within the cache can be
pointed to with aux_data and should be of length aux_data_len.  This would
typically be used for storing coherency data.

The netfs may pass an arbitrary value in netfs_data and this will be presented
to it in the event of any calling back.  This may also be used in tracing or
logging of messages.

The cache tracks the size of the data attached to an object and this set to be
object_size.  For indices, this should be 0.  This value will be passed to the
->check_aux() callback.

Note that this function never returns an error - all errors are handled
Note that this function never returns an error - all errors are handled
internally.  It may, however, return NULL to indicate no cookie.  It is quite
internally.  It may, however, return NULL to indicate no cookie.  It is quite
acceptable to pass this token back to this function as the parent to another
acceptable to pass this token back to this function as the parent to another
@@ -355,30 +339,24 @@ must be enabled to do anything with it. A disabled cookie can be enabled by
calling fscache_enable_cookie() (see below).
calling fscache_enable_cookie() (see below).


For example, with AFS, a cell would be added to the primary index.  This index
For example, with AFS, a cell would be added to the primary index.  This index
entry would have a dependent inode containing a volume location index for the
entry would have a dependent inode containing volume mappings within this cell:
volume mappings within this cell:


	cell->cache =
	cell->cache =
		fscache_acquire_cookie(afs_cache_netfs.primary_index,
		fscache_acquire_cookie(afs_cache_netfs.primary_index,
				       &afs_cell_cache_index_def,
				       &afs_cell_cache_index_def,
				       cell, true);
				       cell->name, strlen(cell->name),
				       NULL, 0,
				       cell, 0, true);


Then when a volume location was accessed, it would be entered into the cell's
And then a particular volume could be added to that index by ID, creating
index and an inode would be allocated that acts as a volume type and hash chain
another index for vnodes (AFS inode equivalents):
combination:

	vlocation->cache =
		fscache_acquire_cookie(cell->cache,
				       &afs_vlocation_cache_index_def,
				       vlocation, true);

And then a particular flavour of volume (R/O for example) could be added to
that index, creating another index for vnodes (AFS inode equivalents):


	volume->cache =
	volume->cache =
		fscache_acquire_cookie(vlocation->cache,
		fscache_acquire_cookie(volume->cell->cache,
				       &afs_volume_cache_index_def,
				       &afs_volume_cache_index_def,
				       volume, true);
				       &volume->vid, sizeof(volume->vid),
				       NULL, 0,
				       volume, 0, true);




======================
======================
@@ -392,7 +370,9 @@ the object definition should be something other than index type.
	vnode->cache =
	vnode->cache =
		fscache_acquire_cookie(volume->cache,
		fscache_acquire_cookie(volume->cache,
				       &afs_vnode_cache_object_def,
				       &afs_vnode_cache_object_def,
				       vnode, true);
				       &key, sizeof(key),
				       &aux, sizeof(aux),
				       vnode, vnode->status.size, true);




=================================
=================================
@@ -408,7 +388,9 @@ it would be some other type of object such as a data file.
	xattr->cache =
	xattr->cache =
		fscache_acquire_cookie(vnode->cache,
		fscache_acquire_cookie(vnode->cache,
				       &afs_xattr_cache_object_def,
				       &afs_xattr_cache_object_def,
				       xattr, true);
				       &xattr->name, strlen(xattr->name),
				       NULL, 0,
				       xattr, strlen(xattr->val), true);


Miscellaneous objects might be used to store extended attributes or directory
Miscellaneous objects might be used to store extended attributes or directory
entries for example.
entries for example.
@@ -425,8 +407,7 @@ cache to adjust its metadata for data tracking appropriately:
	int fscache_attr_changed(struct fscache_cookie *cookie);
	int fscache_attr_changed(struct fscache_cookie *cookie);


The cache will return -ENOBUFS if there is no backing cache or if there is no
The cache will return -ENOBUFS if there is no backing cache or if there is no
space to allocate any extra metadata required in the cache.  The attributes
space to allocate any extra metadata required in the cache.
will be accessed with the get_attr() cookie definition operation.


Note that attempts to read or write data pages in the cache over this size may
Note that attempts to read or write data pages in the cache over this size may
be rebuffed with -ENOBUFS.
be rebuffed with -ENOBUFS.
@@ -551,12 +532,13 @@ written back to the cache:


	int fscache_write_page(struct fscache_cookie *cookie,
	int fscache_write_page(struct fscache_cookie *cookie,
			       struct page *page,
			       struct page *page,
			       loff_t object_size,
			       gfp_t gfp);
			       gfp_t gfp);


The cookie argument must specify a data file cookie, the page specified should
The cookie argument must specify a data file cookie, the page specified should
contain the data to be written (and is also used to specify the page number),
contain the data to be written (and is also used to specify the page number),
and the gfp argument is used to control how any memory allocations made are
object_size is the revised size of the object and the gfp argument is used to
satisfied.
control how any memory allocations made are satisfied.


The page must have first been read or allocated successfully and must not have
The page must have first been read or allocated successfully and must not have
been uncached before writing is performed.
been uncached before writing is performed.
@@ -717,21 +699,23 @@ INDEX AND DATA FILE CONSISTENCY
To find out whether auxiliary data for an object is up to data within the
To find out whether auxiliary data for an object is up to data within the
cache, the following function can be called:
cache, the following function can be called:


	int fscache_check_consistency(struct fscache_cookie *cookie)
	int fscache_check_consistency(struct fscache_cookie *cookie,
				      const void *aux_data);


This will call back to the netfs to check whether the auxiliary data associated
This will call back to the netfs to check whether the auxiliary data associated
with a cookie is correct.  It returns 0 if it is and -ESTALE if it isn't; it
with a cookie is correct; if aux_data is non-NULL, it will update the auxiliary
may also return -ENOMEM and -ERESTARTSYS.
data buffer first.  It returns 0 if it is and -ESTALE if it isn't; it may also
return -ENOMEM and -ERESTARTSYS.


To request an update of the index data for an index or other object, the
To request an update of the index data for an index or other object, the
following function should be called:
following function should be called:


	void fscache_update_cookie(struct fscache_cookie *cookie);
	void fscache_update_cookie(struct fscache_cookie *cookie,
				   const void *aux_data);


This function will refer back to the netfs_data pointer stored in the cookie by
This function will update the cookie's auxiliary data buffer from aux_data if
the acquisition function to obtain the data to write into each revised index
that is non-NULL and then schedule this to be stored on disk.  The update
entry.  The update method in the parent index definition will be called to
method in the parent index definition will be called to transfer the data.
transfer the data.


Note that partial updates may happen automatically at other times, such as when
Note that partial updates may happen automatically at other times, such as when
data blocks are added to a data file object.
data blocks are added to a data file object.
@@ -750,6 +734,7 @@ The initial enablement state is set by fscache_acquire_cookie(), but the cookie
can be enabled or disabled later.  To disable a cookie, call:
can be enabled or disabled later.  To disable a cookie, call:


	void fscache_disable_cookie(struct fscache_cookie *cookie,
	void fscache_disable_cookie(struct fscache_cookie *cookie,
				    const void *aux_data,
    				    bool invalidate);
    				    bool invalidate);


If the cookie is not already disabled, this locks the cookie against other
If the cookie is not already disabled, this locks the cookie against other
@@ -764,6 +749,8 @@ markings are cleared up.
Cookies can be enabled or reenabled with:
Cookies can be enabled or reenabled with:


    	void fscache_enable_cookie(struct fscache_cookie *cookie,
    	void fscache_enable_cookie(struct fscache_cookie *cookie,
				   const void *aux_data,
				   loff_t object_size,
    				   bool (*can_enable)(void *data),
    				   bool (*can_enable)(void *data),
    				   void *data)
    				   void *data)


@@ -777,6 +764,12 @@ ruling as to whether or not enablement should actually be permitted to begin.
All possible failures are handled internally.  The cookie will only be marked
All possible failures are handled internally.  The cookie will only be marked
as enabled if provisional backing objects are allocated.
as enabled if provisional backing objects are allocated.


The object's data size is updated from object_size and is passed to the
->check_aux() function.

In both cases, the cookie's auxiliary data buffer is updated from aux_data if
that is non-NULL inside the enablement lock before proceeding.



===============================
===============================
MISCELLANEOUS COOKIE OPERATIONS
MISCELLANEOUS COOKIE OPERATIONS
@@ -823,6 +816,7 @@ COOKIE UNREGISTRATION
To get rid of a cookie, this function should be called.
To get rid of a cookie, this function should be called.


	void fscache_relinquish_cookie(struct fscache_cookie *cookie,
	void fscache_relinquish_cookie(struct fscache_cookie *cookie,
				       const void *aux_data,
				       bool retire);
				       bool retire);


If retire is non-zero, then the object will be marked for recycling, and all
If retire is non-zero, then the object will be marked for recycling, and all
@@ -833,6 +827,9 @@ If retire is zero, then the object may be available again when next the
acquisition function is called.  Retirement here will overrule the pinning on a
acquisition function is called.  Retirement here will overrule the pinning on a
cookie.
cookie.


The cookie's auxiliary data will be updated from aux_data if that is non-NULL
so that the cache can lazily update it on disk.

One very important note - relinquish must NOT be called for a cookie unless all
One very important note - relinquish must NOT be called for a cookie unless all
the cookies for "child" indices, objects and pages have been relinquished
the cookies for "child" indices, objects and pages have been relinquished
first.
first.
+33 −67
Original line number Original line Diff line number Diff line
@@ -55,42 +55,27 @@ int v9fs_random_cachetag(struct v9fs_session_info *v9ses)
	return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies);
	return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies);
}
}


static uint16_t v9fs_cache_session_get_key(const void *cookie_netfs_data,
					   void *buffer, uint16_t bufmax)
{
	struct v9fs_session_info *v9ses;
	uint16_t klen = 0;

	v9ses = (struct v9fs_session_info *)cookie_netfs_data;
	p9_debug(P9_DEBUG_FSC, "session %p buf %p size %u\n",
		 v9ses, buffer, bufmax);

	if (v9ses->cachetag)
		klen = strlen(v9ses->cachetag);

	if (klen > bufmax)
		return 0;

	memcpy(buffer, v9ses->cachetag, klen);
	p9_debug(P9_DEBUG_FSC, "cache session tag %s\n", v9ses->cachetag);
	return klen;
}

const struct fscache_cookie_def v9fs_cache_session_index_def = {
const struct fscache_cookie_def v9fs_cache_session_index_def = {
	.name		= "9P.session",
	.name		= "9P.session",
	.type		= FSCACHE_COOKIE_TYPE_INDEX,
	.type		= FSCACHE_COOKIE_TYPE_INDEX,
	.get_key	= v9fs_cache_session_get_key,
};
};


void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
{
{
	/* If no cache session tag was specified, we generate a random one. */
	/* If no cache session tag was specified, we generate a random one. */
	if (!v9ses->cachetag)
	if (!v9ses->cachetag) {
		v9fs_random_cachetag(v9ses);
		if (v9fs_random_cachetag(v9ses) < 0) {
			v9ses->fscache = NULL;
			return;
		}
	}


	v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index,
	v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index,
						&v9fs_cache_session_index_def,
						&v9fs_cache_session_index_def,
						v9ses, true);
						v9ses->cachetag,
						strlen(v9ses->cachetag),
						NULL, 0,
						v9ses, 0, true);
	p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n",
	p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n",
		 v9ses, v9ses->fscache);
		 v9ses, v9ses->fscache);
}
}
@@ -99,45 +84,15 @@ void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses)
{
{
	p9_debug(P9_DEBUG_FSC, "session %p put cookie %p\n",
	p9_debug(P9_DEBUG_FSC, "session %p put cookie %p\n",
		 v9ses, v9ses->fscache);
		 v9ses, v9ses->fscache);
	fscache_relinquish_cookie(v9ses->fscache, 0);
	fscache_relinquish_cookie(v9ses->fscache, NULL, false);
	v9ses->fscache = NULL;
	v9ses->fscache = NULL;
}
}



static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data,
					 void *buffer, uint16_t bufmax)
{
	const struct v9fs_inode *v9inode = cookie_netfs_data;
	memcpy(buffer, &v9inode->qid.path, sizeof(v9inode->qid.path));
	p9_debug(P9_DEBUG_FSC, "inode %p get key %llu\n",
		 &v9inode->vfs_inode, v9inode->qid.path);
	return sizeof(v9inode->qid.path);
}

static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data,
				      uint64_t *size)
{
	const struct v9fs_inode *v9inode = cookie_netfs_data;
	*size = i_size_read(&v9inode->vfs_inode);

	p9_debug(P9_DEBUG_FSC, "inode %p get attr %llu\n",
		 &v9inode->vfs_inode, *size);
}

static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data,
					 void *buffer, uint16_t buflen)
{
	const struct v9fs_inode *v9inode = cookie_netfs_data;
	memcpy(buffer, &v9inode->qid.version, sizeof(v9inode->qid.version));
	p9_debug(P9_DEBUG_FSC, "inode %p get aux %u\n",
		 &v9inode->vfs_inode, v9inode->qid.version);
	return sizeof(v9inode->qid.version);
}

static enum
static enum
fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
					    const void *buffer,
					    const void *buffer,
					    uint16_t buflen)
					    uint16_t buflen,
					    loff_t object_size)
{
{
	const struct v9fs_inode *v9inode = cookie_netfs_data;
	const struct v9fs_inode *v9inode = cookie_netfs_data;


@@ -154,9 +109,6 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
const struct fscache_cookie_def v9fs_cache_inode_index_def = {
const struct fscache_cookie_def v9fs_cache_inode_index_def = {
	.name		= "9p.inode",
	.name		= "9p.inode",
	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
	.get_key	= v9fs_cache_inode_get_key,
	.get_attr	= v9fs_cache_inode_get_attr,
	.get_aux	= v9fs_cache_inode_get_aux,
	.check_aux	= v9fs_cache_inode_check_aux,
	.check_aux	= v9fs_cache_inode_check_aux,
};
};


@@ -175,7 +127,13 @@ void v9fs_cache_inode_get_cookie(struct inode *inode)
	v9ses = v9fs_inode2v9ses(inode);
	v9ses = v9fs_inode2v9ses(inode);
	v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
	v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
						  &v9fs_cache_inode_index_def,
						  &v9fs_cache_inode_index_def,
						  v9inode, true);
						  &v9inode->qid.path,
						  sizeof(v9inode->qid.path),
						  &v9inode->qid.version,
						  sizeof(v9inode->qid.version),
						  v9inode,
						  i_size_read(&v9inode->vfs_inode),
						  true);


	p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
	p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
		 inode, v9inode->fscache);
		 inode, v9inode->fscache);
@@ -190,7 +148,8 @@ void v9fs_cache_inode_put_cookie(struct inode *inode)
	p9_debug(P9_DEBUG_FSC, "inode %p put cookie %p\n",
	p9_debug(P9_DEBUG_FSC, "inode %p put cookie %p\n",
		 inode, v9inode->fscache);
		 inode, v9inode->fscache);


	fscache_relinquish_cookie(v9inode->fscache, 0);
	fscache_relinquish_cookie(v9inode->fscache, &v9inode->qid.version,
				  false);
	v9inode->fscache = NULL;
	v9inode->fscache = NULL;
}
}


@@ -203,7 +162,7 @@ void v9fs_cache_inode_flush_cookie(struct inode *inode)
	p9_debug(P9_DEBUG_FSC, "inode %p flush cookie %p\n",
	p9_debug(P9_DEBUG_FSC, "inode %p flush cookie %p\n",
		 inode, v9inode->fscache);
		 inode, v9inode->fscache);


	fscache_relinquish_cookie(v9inode->fscache, 1);
	fscache_relinquish_cookie(v9inode->fscache, NULL, true);
	v9inode->fscache = NULL;
	v9inode->fscache = NULL;
}
}


@@ -236,12 +195,18 @@ void v9fs_cache_inode_reset_cookie(struct inode *inode)
	old = v9inode->fscache;
	old = v9inode->fscache;


	mutex_lock(&v9inode->fscache_lock);
	mutex_lock(&v9inode->fscache_lock);
	fscache_relinquish_cookie(v9inode->fscache, 1);
	fscache_relinquish_cookie(v9inode->fscache, NULL, true);


	v9ses = v9fs_inode2v9ses(inode);
	v9ses = v9fs_inode2v9ses(inode);
	v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
	v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
						  &v9fs_cache_inode_index_def,
						  &v9fs_cache_inode_index_def,
						  v9inode, true);
						  &v9inode->qid.path,
						  sizeof(v9inode->qid.path),
						  &v9inode->qid.version,
						  sizeof(v9inode->qid.version),
						  v9inode,
						  i_size_read(&v9inode->vfs_inode),
						  true);
	p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n",
	p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n",
		 inode, old, v9inode->fscache);
		 inode, old, v9inode->fscache);


@@ -367,7 +332,8 @@ void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
	const struct v9fs_inode *v9inode = V9FS_I(inode);
	const struct v9fs_inode *v9inode = V9FS_I(inode);


	p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
	p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
	ret = fscache_write_page(v9inode->fscache, page, GFP_KERNEL);
	ret = fscache_write_page(v9inode->fscache, page,
				 i_size_read(&v9inode->vfs_inode), GFP_KERNEL);
	p9_debug(P9_DEBUG_FSC, "ret =  %d\n", ret);
	p9_debug(P9_DEBUG_FSC, "ret =  %d\n", ret);
	if (ret != 0)
	if (ret != 0)
		v9fs_uncache_page(inode, page);
		v9fs_uncache_page(inode, page);
+8 −142
Original line number Original line Diff line number Diff line
@@ -12,167 +12,39 @@
#include <linux/sched.h>
#include <linux/sched.h>
#include "internal.h"
#include "internal.h"


static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data,
				       void *buffer, uint16_t buflen);
static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data,
					 void *buffer, uint16_t buflen);

static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data,
					void *buffer, uint16_t buflen);
static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
				     uint64_t *size);
static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data,
					void *buffer, uint16_t buflen);
static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
						       const void *buffer,
						       const void *buffer,
						       uint16_t buflen);
						       uint16_t buflen,
						       loff_t object_size);


struct fscache_netfs afs_cache_netfs = {
struct fscache_netfs afs_cache_netfs = {
	.name			= "afs",
	.name			= "afs",
	.version		= 1,
	.version		= 2,
};
};


struct fscache_cookie_def afs_cell_cache_index_def = {
struct fscache_cookie_def afs_cell_cache_index_def = {
	.name		= "AFS.cell",
	.name		= "AFS.cell",
	.type		= FSCACHE_COOKIE_TYPE_INDEX,
	.type		= FSCACHE_COOKIE_TYPE_INDEX,
	.get_key	= afs_cell_cache_get_key,
};
};


struct fscache_cookie_def afs_volume_cache_index_def = {
struct fscache_cookie_def afs_volume_cache_index_def = {
	.name		= "AFS.volume",
	.name		= "AFS.volume",
	.type		= FSCACHE_COOKIE_TYPE_INDEX,
	.type		= FSCACHE_COOKIE_TYPE_INDEX,
	.get_key	= afs_volume_cache_get_key,
};
};


struct fscache_cookie_def afs_vnode_cache_index_def = {
struct fscache_cookie_def afs_vnode_cache_index_def = {
	.name		= "AFS.vnode",
	.name		= "AFS.vnode",
	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
	.get_key		= afs_vnode_cache_get_key,
	.get_attr		= afs_vnode_cache_get_attr,
	.get_aux		= afs_vnode_cache_get_aux,
	.check_aux	= afs_vnode_cache_check_aux,
	.check_aux	= afs_vnode_cache_check_aux,
};
};


/*
 * set the key for the index entry
 */
static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data,
				       void *buffer, uint16_t bufmax)
{
	const struct afs_cell *cell = cookie_netfs_data;
	uint16_t klen;

	_enter("%p,%p,%u", cell, buffer, bufmax);

	klen = strlen(cell->name);
	if (klen > bufmax)
		return 0;

	memcpy(buffer, cell->name, klen);
	return klen;
}

/*****************************************************************************/
/*
 * set the key for the volume index entry
 */
static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data,
					 void *buffer, uint16_t bufmax)
{
	const struct afs_volume *volume = cookie_netfs_data;
	struct {
		u64 volid;
	} __packed key;

	_enter("{%u},%p,%u", volume->type, buffer, bufmax);

	if (bufmax < sizeof(key))
		return 0;

	key.volid = volume->vid;
	memcpy(buffer, &key, sizeof(key));
	return sizeof(key);
}

/*****************************************************************************/
/*
 * set the key for the index entry
 */
static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data,
					void *buffer, uint16_t bufmax)
{
	const struct afs_vnode *vnode = cookie_netfs_data;
	struct {
		u32 vnode_id[3];
	} __packed key;

	_enter("{%x,%x,%llx},%p,%u",
	       vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
	       buffer, bufmax);

	/* Allow for a 96-bit key */
	memset(&key, 0, sizeof(key));
	key.vnode_id[0] = vnode->fid.vnode;
	key.vnode_id[1] = 0;
	key.vnode_id[2] = 0;

	if (sizeof(key) > bufmax)
		return 0;

	memcpy(buffer, &key, sizeof(key));
	return sizeof(key);
}

/*
 * provide updated file attributes
 */
static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
				     uint64_t *size)
{
	const struct afs_vnode *vnode = cookie_netfs_data;

	_enter("{%x,%x,%llx},",
	       vnode->fid.vnode, vnode->fid.unique,
	       vnode->status.data_version);

	*size = vnode->status.size;
}

struct afs_vnode_cache_aux {
	u64 data_version;
	u32 fid_unique;
} __packed;

/*
 * provide new auxiliary cache data
 */
static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data,
					void *buffer, uint16_t bufmax)
{
	const struct afs_vnode *vnode = cookie_netfs_data;
	struct afs_vnode_cache_aux aux;

	_enter("{%x,%x,%Lx},%p,%u",
	       vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
	       buffer, bufmax);

	memset(&aux, 0, sizeof(aux));
	aux.data_version = vnode->status.data_version;
	aux.fid_unique = vnode->fid.unique;

	if (bufmax < sizeof(aux))
		return 0;

	memcpy(buffer, &aux, sizeof(aux));
	return sizeof(aux);
}

/*
/*
 * check that the auxiliary data indicates that the entry is still valid
 * check that the auxiliary data indicates that the entry is still valid
 */
 */
static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
						       const void *buffer,
						       const void *buffer,
						       uint16_t buflen)
						       uint16_t buflen,
						       loff_t object_size)
{
{
	struct afs_vnode *vnode = cookie_netfs_data;
	struct afs_vnode *vnode = cookie_netfs_data;
	struct afs_vnode_cache_aux aux;
	struct afs_vnode_cache_aux aux;
@@ -189,12 +61,6 @@ static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
		return FSCACHE_CHECKAUX_OBSOLETE;
		return FSCACHE_CHECKAUX_OBSOLETE;
	}
	}


	if (vnode->fid.unique != aux.fid_unique) {
		_leave(" = OBSOLETE [uniq %x != %x]",
		       aux.fid_unique, vnode->fid.unique);
		return FSCACHE_CHECKAUX_OBSOLETE;
	}

	if (vnode->status.data_version != aux.data_version) {
	if (vnode->status.data_version != aux.data_version) {
		_leave(" = OBSOLETE [vers %llx != %llx]",
		_leave(" = OBSOLETE [vers %llx != %llx]",
		       aux.data_version, vnode->status.data_version);
		       aux.data_version, vnode->status.data_version);
+4 −2
Original line number Original line Diff line number Diff line
@@ -522,7 +522,9 @@ static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell)
#ifdef CONFIG_AFS_FSCACHE
#ifdef CONFIG_AFS_FSCACHE
	cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index,
	cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index,
					     &afs_cell_cache_index_def,
					     &afs_cell_cache_index_def,
					     cell, true);
					     cell->name, strlen(cell->name),
					     NULL, 0,
					     cell, 0, true);
#endif
#endif
	ret = afs_proc_cell_setup(net, cell);
	ret = afs_proc_cell_setup(net, cell);
	if (ret < 0)
	if (ret < 0)
@@ -547,7 +549,7 @@ static void afs_deactivate_cell(struct afs_net *net, struct afs_cell *cell)
	spin_unlock(&net->proc_cells_lock);
	spin_unlock(&net->proc_cells_lock);


#ifdef CONFIG_AFS_FSCACHE
#ifdef CONFIG_AFS_FSCACHE
	fscache_relinquish_cookie(cell->cache, 0);
	fscache_relinquish_cookie(cell->cache, NULL, false);
	cell->cache = NULL;
	cell->cache = NULL;
#endif
#endif


+4 −2
Original line number Original line Diff line number Diff line
@@ -339,7 +339,8 @@ int afs_page_filler(void *data, struct page *page)
		/* send the page to the cache */
		/* send the page to the cache */
#ifdef CONFIG_AFS_FSCACHE
#ifdef CONFIG_AFS_FSCACHE
		if (PageFsCache(page) &&
		if (PageFsCache(page) &&
		    fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
		    fscache_write_page(vnode->cache, page, vnode->status.size,
				       GFP_KERNEL) != 0) {
			fscache_uncache_page(vnode->cache, page);
			fscache_uncache_page(vnode->cache, page);
			BUG_ON(PageFsCache(page));
			BUG_ON(PageFsCache(page));
		}
		}
@@ -403,7 +404,8 @@ static void afs_readpages_page_done(struct afs_call *call, struct afs_read *req)
	/* send the page to the cache */
	/* send the page to the cache */
#ifdef CONFIG_AFS_FSCACHE
#ifdef CONFIG_AFS_FSCACHE
	if (PageFsCache(page) &&
	if (PageFsCache(page) &&
	    fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
	    fscache_write_page(vnode->cache, page, vnode->status.size,
			       GFP_KERNEL) != 0) {
		fscache_uncache_page(vnode->cache, page);
		fscache_uncache_page(vnode->cache, page);
		BUG_ON(PageFsCache(page));
		BUG_ON(PageFsCache(page));
	}
	}
Loading