This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / fs / fscache / fsdef.c
1 /* fsdef.c: filesystem index definition
2  *
3  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/module.h>
13 #include "fscache-int.h"
14
15 static uint16_t fscache_fsdef_netfs_get_key(const void *cookie_netfs_data,
16                                             void *buffer, uint16_t bufmax);
17
18 static uint16_t fscache_fsdef_netfs_get_aux(const void *cookie_netfs_data,
19                                             void *buffer, uint16_t bufmax);
20
21 static fscache_checkaux_t fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
22                                                         const void *data,
23                                                         uint16_t datalen);
24
25 struct fscache_cookie_def fscache_fsdef_netfs_def = {
26         .name           = "FSDEF.netfs",
27         .type           = FSCACHE_COOKIE_TYPE_INDEX,
28         .get_key        = fscache_fsdef_netfs_get_key,
29         .get_aux        = fscache_fsdef_netfs_get_aux,
30         .check_aux      = fscache_fsdef_netfs_check_aux,
31 };
32
33 struct fscache_cookie fscache_fsdef_index = {
34         .usage          = ATOMIC_INIT(1),
35         .def            = NULL,
36         .sem            = __RWSEM_INITIALIZER(fscache_fsdef_index.sem),
37         .backing_objects = HLIST_HEAD_INIT,
38 };
39
40 EXPORT_SYMBOL(fscache_fsdef_index);
41
42 /*****************************************************************************/
43 /*
44  * get the key data for an FSDEF index record
45  */
46 static uint16_t fscache_fsdef_netfs_get_key(const void *cookie_netfs_data,
47                                             void *buffer, uint16_t bufmax)
48 {
49         const struct fscache_netfs *netfs = cookie_netfs_data;
50         unsigned klen;
51
52         _enter("{%s.%u},", netfs->name, netfs->version);
53
54         klen = strlen(netfs->name);
55         if (klen > bufmax)
56                 return 0;
57
58         memcpy(buffer, netfs->name, klen);
59         return klen;
60 }
61
62 /*****************************************************************************/
63 /*
64  * get the auxilliary data for an FSDEF index record
65  */
66 static uint16_t fscache_fsdef_netfs_get_aux(const void *cookie_netfs_data,
67                                             void *buffer, uint16_t bufmax)
68 {
69         const struct fscache_netfs *netfs = cookie_netfs_data;
70         unsigned dlen;
71
72         _enter("{%s.%u},", netfs->name, netfs->version);
73
74         dlen = sizeof(uint32_t);
75         if (dlen > bufmax)
76                 return 0;
77
78         memcpy(buffer, &netfs->version, dlen);
79         return dlen;
80 }
81
82 /*****************************************************************************/
83 /*
84  * check that the version stored in the auxilliary data is correct
85  */
86 static fscache_checkaux_t fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
87                                                         const void *data,
88                                                         uint16_t datalen)
89 {
90         struct fscache_netfs *netfs = cookie_netfs_data;
91         uint32_t version;
92
93         _enter("{%s},,%hu", netfs->name, datalen);
94
95         if (datalen != sizeof(version)) {
96                 _leave(" = OBSOLETE [dl=%d v=%d]",
97                        datalen, sizeof(version));
98                 return FSCACHE_CHECKAUX_OBSOLETE;
99         }
100
101         memcpy(&version, data, sizeof(version));
102         if (version != netfs->version) {
103                 _leave(" = OBSOLETE [ver=%x net=%x]",
104                        version, netfs->version);
105                 return FSCACHE_CHECKAUX_OBSOLETE;
106         }
107
108         _leave(" = OKAY");
109         return FSCACHE_CHECKAUX_OKAY;
110 }