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 | /* |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 49 | * Server object for FS-Cache |
| 50 | */ |
| 51 | const struct fscache_cookie_def cifs_fscache_server_index_def = { |
| 52 | .name = "CIFS.server", |
| 53 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 54 | }; |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 55 | |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 56 | static enum |
| 57 | fscache_checkaux cifs_fscache_super_check_aux(void *cookie_netfs_data, |
| 58 | const void *data, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 59 | uint16_t datalen, |
| 60 | loff_t object_size) |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 61 | { |
| 62 | struct cifs_fscache_super_auxdata auxdata; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 63 | const struct cifs_tcon *tcon = cookie_netfs_data; |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 64 | |
| 65 | if (datalen != sizeof(auxdata)) |
| 66 | return FSCACHE_CHECKAUX_OBSOLETE; |
| 67 | |
| 68 | memset(&auxdata, 0, sizeof(auxdata)); |
| 69 | auxdata.resource_id = tcon->resource_id; |
Steve French | 5865985 | 2020-06-05 17:19:46 -0500 | [diff] [blame] | 70 | auxdata.vol_create_time = tcon->vol_create_time; |
| 71 | auxdata.vol_serial_number = tcon->vol_serial_number; |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 72 | |
| 73 | if (memcmp(data, &auxdata, datalen) != 0) |
| 74 | return FSCACHE_CHECKAUX_OBSOLETE; |
| 75 | |
| 76 | return FSCACHE_CHECKAUX_OKAY; |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Superblock object for FS-Cache |
| 81 | */ |
| 82 | const struct fscache_cookie_def cifs_fscache_super_index_def = { |
| 83 | .name = "CIFS.super", |
| 84 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 85 | .check_aux = cifs_fscache_super_check_aux, |
| 86 | }; |
| 87 | |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 88 | static enum |
| 89 | fscache_checkaux cifs_fscache_inode_check_aux(void *cookie_netfs_data, |
| 90 | const void *data, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 91 | uint16_t datalen, |
| 92 | loff_t object_size) |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 93 | { |
| 94 | struct cifs_fscache_inode_auxdata auxdata; |
| 95 | struct cifsInodeInfo *cifsi = cookie_netfs_data; |
| 96 | |
| 97 | if (datalen != sizeof(auxdata)) |
| 98 | return FSCACHE_CHECKAUX_OBSOLETE; |
| 99 | |
| 100 | memset(&auxdata, 0, sizeof(auxdata)); |
| 101 | auxdata.eof = cifsi->server_eof; |
Arnd Bergmann | cbedead | 2018-06-19 17:27:59 +0200 | [diff] [blame] | 102 | auxdata.last_write_time_sec = cifsi->vfs_inode.i_mtime.tv_sec; |
| 103 | auxdata.last_change_time_sec = cifsi->vfs_inode.i_ctime.tv_sec; |
| 104 | auxdata.last_write_time_nsec = cifsi->vfs_inode.i_mtime.tv_nsec; |
| 105 | auxdata.last_change_time_nsec = cifsi->vfs_inode.i_ctime.tv_nsec; |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 106 | |
| 107 | if (memcmp(data, &auxdata, datalen) != 0) |
| 108 | return FSCACHE_CHECKAUX_OBSOLETE; |
| 109 | |
| 110 | return FSCACHE_CHECKAUX_OKAY; |
| 111 | } |
| 112 | |
| 113 | const struct fscache_cookie_def cifs_fscache_inode_object_def = { |
| 114 | .name = "CIFS.uniqueid", |
| 115 | .type = FSCACHE_COOKIE_TYPE_DATAFILE, |
Suresh Jayaraman | 9451a9a | 2010-07-05 18:12:45 +0530 | [diff] [blame] | 116 | .check_aux = cifs_fscache_inode_check_aux, |
| 117 | }; |