2019-05-21 00:08:01 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-04-03 22:42:38 +07:00
|
|
|
/* FS-Cache netfs (client) registration
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define FSCACHE_DEBUG_LEVEL COOKIE
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* register a network filesystem for caching
|
|
|
|
*/
|
|
|
|
int __fscache_register_netfs(struct fscache_netfs *netfs)
|
|
|
|
{
|
2018-04-04 19:41:28 +07:00
|
|
|
struct fscache_cookie *candidate, *cookie;
|
2009-04-03 22:42:38 +07:00
|
|
|
|
|
|
|
_enter("{%s}", netfs->name);
|
|
|
|
|
|
|
|
/* allocate a cookie for the primary index */
|
2018-04-04 19:41:28 +07:00
|
|
|
candidate = fscache_alloc_cookie(&fscache_fsdef_index,
|
|
|
|
&fscache_fsdef_netfs_def,
|
|
|
|
netfs->name, strlen(netfs->name),
|
|
|
|
&netfs->version, sizeof(netfs->version),
|
|
|
|
netfs, 0);
|
|
|
|
if (!candidate) {
|
2009-04-03 22:42:38 +07:00
|
|
|
_leave(" = -ENOMEM");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2018-04-04 19:41:28 +07:00
|
|
|
candidate->flags = 1 << FSCACHE_COOKIE_ENABLED;
|
2009-04-03 22:42:38 +07:00
|
|
|
|
|
|
|
/* check the netfs type is not already present */
|
2018-04-04 19:41:28 +07:00
|
|
|
cookie = fscache_hash_cookie(candidate);
|
|
|
|
if (!cookie)
|
|
|
|
goto already_registered;
|
|
|
|
if (cookie != candidate) {
|
|
|
|
trace_fscache_cookie(candidate, fscache_cookie_discard, 1);
|
|
|
|
fscache_free_cookie(candidate);
|
2009-04-03 22:42:38 +07:00
|
|
|
}
|
|
|
|
|
2018-04-04 19:41:27 +07:00
|
|
|
fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs);
|
2015-11-04 22:20:24 +07:00
|
|
|
atomic_inc(&cookie->parent->n_children);
|
2015-11-04 22:20:15 +07:00
|
|
|
|
2015-11-04 22:20:24 +07:00
|
|
|
netfs->primary_index = cookie;
|
2009-04-03 22:42:38 +07:00
|
|
|
|
2014-06-05 06:05:38 +07:00
|
|
|
pr_notice("Netfs '%s' registered for caching\n", netfs->name);
|
2018-04-04 19:41:27 +07:00
|
|
|
trace_fscache_netfs(netfs);
|
2018-04-04 19:41:28 +07:00
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
2009-04-03 22:42:38 +07:00
|
|
|
|
|
|
|
already_registered:
|
2018-04-04 19:41:28 +07:00
|
|
|
fscache_cookie_put(candidate, fscache_cookie_put_dup_netfs);
|
|
|
|
_leave(" = -EEXIST");
|
|
|
|
return -EEXIST;
|
2009-04-03 22:42:38 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__fscache_register_netfs);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* unregister a network filesystem from the cache
|
|
|
|
* - all cookies must have been released first
|
|
|
|
*/
|
|
|
|
void __fscache_unregister_netfs(struct fscache_netfs *netfs)
|
|
|
|
{
|
|
|
|
_enter("{%s.%u}", netfs->name, netfs->version);
|
|
|
|
|
2018-04-04 19:41:28 +07:00
|
|
|
fscache_relinquish_cookie(netfs->primary_index, NULL, false);
|
2018-04-04 19:41:28 +07:00
|
|
|
pr_notice("Netfs '%s' unregistered from caching\n", netfs->name);
|
2009-04-03 22:42:38 +07:00
|
|
|
|
|
|
|
_leave("");
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__fscache_unregister_netfs);
|