Linux 6.9-rc1
[linux-2.6-microblaze.git] / fs / cifs / cache.c
1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3  *   fs/cifs/cache.c - CIFS filesystem cache index structure definitions
4  *
5  *   Copyright (c) 2010 Novell, Inc.
6  *   Authors(s): Suresh Jayaraman (sjayaraman@suse.de>
7  *
8  */
9 #include "fscache.h"
10 #include "cifs_debug.h"
11
12 /*
13  * CIFS filesystem definition for FS-Cache
14  */
15 struct fscache_netfs cifs_fscache_netfs = {
16         .name = "cifs",
17         .version = 0,
18 };
19
20 /*
21  * Register CIFS for caching with FS-Cache
22  */
23 int cifs_fscache_register(void)
24 {
25         return fscache_register_netfs(&cifs_fscache_netfs);
26 }
27
28 /*
29  * Unregister CIFS for caching
30  */
31 void cifs_fscache_unregister(void)
32 {
33         fscache_unregister_netfs(&cifs_fscache_netfs);
34 }
35
36 /*
37  * Server object for FS-Cache
38  */
39 const struct fscache_cookie_def cifs_fscache_server_index_def = {
40         .name = "CIFS.server",
41         .type = FSCACHE_COOKIE_TYPE_INDEX,
42 };
43
44 static enum
45 fscache_checkaux cifs_fscache_super_check_aux(void *cookie_netfs_data,
46                                               const void *data,
47                                               uint16_t datalen,
48                                               loff_t object_size)
49 {
50         struct cifs_fscache_super_auxdata auxdata;
51         const struct cifs_tcon *tcon = cookie_netfs_data;
52
53         if (datalen != sizeof(auxdata))
54                 return FSCACHE_CHECKAUX_OBSOLETE;
55
56         memset(&auxdata, 0, sizeof(auxdata));
57         auxdata.resource_id = tcon->resource_id;
58         auxdata.vol_create_time = tcon->vol_create_time;
59         auxdata.vol_serial_number = tcon->vol_serial_number;
60
61         if (memcmp(data, &auxdata, datalen) != 0)
62                 return FSCACHE_CHECKAUX_OBSOLETE;
63
64         return FSCACHE_CHECKAUX_OKAY;
65 }
66
67 /*
68  * Superblock object for FS-Cache
69  */
70 const struct fscache_cookie_def cifs_fscache_super_index_def = {
71         .name = "CIFS.super",
72         .type = FSCACHE_COOKIE_TYPE_INDEX,
73         .check_aux = cifs_fscache_super_check_aux,
74 };
75
76 static enum
77 fscache_checkaux cifs_fscache_inode_check_aux(void *cookie_netfs_data,
78                                               const void *data,
79                                               uint16_t datalen,
80                                               loff_t object_size)
81 {
82         struct cifs_fscache_inode_auxdata auxdata;
83         struct cifsInodeInfo *cifsi = cookie_netfs_data;
84
85         if (datalen != sizeof(auxdata))
86                 return FSCACHE_CHECKAUX_OBSOLETE;
87
88         memset(&auxdata, 0, sizeof(auxdata));
89         auxdata.eof = cifsi->server_eof;
90         auxdata.last_write_time_sec = cifsi->vfs_inode.i_mtime.tv_sec;
91         auxdata.last_change_time_sec = cifsi->vfs_inode.i_ctime.tv_sec;
92         auxdata.last_write_time_nsec = cifsi->vfs_inode.i_mtime.tv_nsec;
93         auxdata.last_change_time_nsec = cifsi->vfs_inode.i_ctime.tv_nsec;
94
95         if (memcmp(data, &auxdata, datalen) != 0)
96                 return FSCACHE_CHECKAUX_OBSOLETE;
97
98         return FSCACHE_CHECKAUX_OKAY;
99 }
100
101 const struct fscache_cookie_def cifs_fscache_inode_object_def = {
102         .name           = "CIFS.uniqueid",
103         .type           = FSCACHE_COOKIE_TYPE_DATAFILE,
104         .check_aux      = cifs_fscache_inode_check_aux,
105 };