diff options
author | Suresh Jayaraman <sjayaraman@suse.de> | 2010-07-05 08:42:15 -0400 |
---|---|---|
committer | Steve French <sfrench@us.ibm.com> | 2010-08-02 08:40:34 -0400 |
commit | 488f1d2d6cc9d665c9f09e4b54f77052732e3058 (patch) | |
tree | 2e240da84cdb009b89508e0fa748bebe71e35766 /fs/cifs/cache.c | |
parent | f579cf3cfd1e19ae5aab6929679d0c04bf1a6284 (diff) |
cifs: define server-level cache index objects and register them
Define server-level cache index objects (as managed by TCP_ServerInfo structs)
and register then with FS-Cache. Each server object is created in the CIFS
top-level index object and is itself an index into which superblock-level
objects are inserted.
The server objects are now keyed by {IPaddress,family,port} tuple.
Signed-off-by: Suresh Jayaraman <sjayaraman@suse.de>
Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs/cifs/cache.c')
-rw-r--r-- | fs/cifs/cache.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/fs/cifs/cache.c b/fs/cifs/cache.c index 1cb5ffb017f1..f46468fb6a90 100644 --- a/fs/cifs/cache.c +++ b/fs/cifs/cache.c | |||
@@ -19,6 +19,7 @@ | |||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 | */ | 20 | */ |
21 | #include "fscache.h" | 21 | #include "fscache.h" |
22 | #include "cifs_debug.h" | ||
22 | 23 | ||
23 | /* | 24 | /* |
24 | * CIFS filesystem definition for FS-Cache | 25 | * CIFS filesystem definition for FS-Cache |
@@ -44,3 +45,64 @@ void cifs_fscache_unregister(void) | |||
44 | fscache_unregister_netfs(&cifs_fscache_netfs); | 45 | fscache_unregister_netfs(&cifs_fscache_netfs); |
45 | } | 46 | } |
46 | 47 | ||
48 | /* | ||
49 | * Key layout of CIFS server cache index object | ||
50 | */ | ||
51 | struct cifs_server_key { | ||
52 | uint16_t family; /* address family */ | ||
53 | uint16_t port; /* IP port */ | ||
54 | union { | ||
55 | struct in_addr ipv4_addr; | ||
56 | struct in6_addr ipv6_addr; | ||
57 | } addr[0]; | ||
58 | }; | ||
59 | |||
60 | /* | ||
61 | * Server object keyed by {IPaddress,port,family} tuple | ||
62 | */ | ||
63 | static uint16_t cifs_server_get_key(const void *cookie_netfs_data, | ||
64 | void *buffer, uint16_t maxbuf) | ||
65 | { | ||
66 | const struct TCP_Server_Info *server = cookie_netfs_data; | ||
67 | const struct sockaddr *sa = (struct sockaddr *) &server->addr.sockAddr; | ||
68 | struct cifs_server_key *key = buffer; | ||
69 | uint16_t key_len = sizeof(struct cifs_server_key); | ||
70 | |||
71 | memset(key, 0, key_len); | ||
72 | |||
73 | /* | ||
74 | * Should not be a problem as sin_family/sin6_family overlays | ||
75 | * sa_family field | ||
76 | */ | ||
77 | switch (sa->sa_family) { | ||
78 | case AF_INET: | ||
79 | key->family = server->addr.sockAddr.sin_family; | ||
80 | key->port = server->addr.sockAddr.sin_port; | ||
81 | key->addr[0].ipv4_addr = server->addr.sockAddr.sin_addr; | ||
82 | key_len += sizeof(key->addr[0].ipv4_addr); | ||
83 | break; | ||
84 | |||
85 | case AF_INET6: | ||
86 | key->family = server->addr.sockAddr6.sin6_family; | ||
87 | key->port = server->addr.sockAddr6.sin6_port; | ||
88 | key->addr[0].ipv6_addr = server->addr.sockAddr6.sin6_addr; | ||
89 | key_len += sizeof(key->addr[0].ipv6_addr); | ||
90 | break; | ||
91 | |||
92 | default: | ||
93 | cERROR(1, "CIFS: Unknown network family '%d'", sa->sa_family); | ||
94 | key_len = 0; | ||
95 | break; | ||
96 | } | ||
97 | |||
98 | return key_len; | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | * Server object for FS-Cache | ||
103 | */ | ||
104 | const struct fscache_cookie_def cifs_fscache_server_index_def = { | ||
105 | .name = "CIFS.server", | ||
106 | .type = FSCACHE_COOKIE_TYPE_INDEX, | ||
107 | .get_key = cifs_server_get_key, | ||
108 | }; | ||