Suresh Jayaraman | f579cf3 | 2010-07-05 18:11:50 +0530 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cache.c - CIFS filesystem cache index structure definitions |
| 3 | * |
| 4 | * Copyright (c) 2010 Novell, Inc. |
| 5 | * Authors(s): Suresh Jayaraman (sjayaraman@suse.de> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Lesser General Public License as published |
| 9 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 15 | * the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | #include "fscache.h" |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame^] | 22 | #include "cifs_debug.h" |
Suresh Jayaraman | f579cf3 | 2010-07-05 18:11:50 +0530 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * CIFS filesystem definition for FS-Cache |
| 26 | */ |
| 27 | struct fscache_netfs cifs_fscache_netfs = { |
| 28 | .name = "cifs", |
| 29 | .version = 0, |
| 30 | }; |
| 31 | |
| 32 | /* |
| 33 | * Register CIFS for caching with FS-Cache |
| 34 | */ |
| 35 | int cifs_fscache_register(void) |
| 36 | { |
| 37 | return fscache_register_netfs(&cifs_fscache_netfs); |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | * Unregister CIFS for caching |
| 42 | */ |
| 43 | void cifs_fscache_unregister(void) |
| 44 | { |
| 45 | fscache_unregister_netfs(&cifs_fscache_netfs); |
| 46 | } |
| 47 | |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame^] | 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 | }; |