Merge tag 'modules-for-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu...
[linux-2.6-microblaze.git] / fs / cifs / dfs_cache.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * DFS referral cache routines
4  *
5  * Copyright (c) 2018-2019 Paulo Alcantara <palcantara@suse.de>
6  */
7
8 #ifndef _CIFS_DFS_CACHE_H
9 #define _CIFS_DFS_CACHE_H
10
11 #include <linux/nls.h>
12 #include <linux/list.h>
13 #include <linux/uuid.h>
14 #include "cifsglob.h"
15
16 struct dfs_cache_tgt_list {
17         int tl_numtgts;
18         struct list_head tl_list;
19 };
20
21 struct dfs_cache_tgt_iterator {
22         char *it_name;
23         int it_path_consumed;
24         struct list_head it_list;
25 };
26
27 int dfs_cache_init(void);
28 void dfs_cache_destroy(void);
29 extern const struct proc_ops dfscache_proc_ops;
30
31 int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses, const struct nls_table *cp,
32                    int remap, const char *path, struct dfs_info3_param *ref,
33                    struct dfs_cache_tgt_list *tgt_list);
34 int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
35                          struct dfs_cache_tgt_list *tgt_list);
36 int dfs_cache_update_tgthint(const unsigned int xid, struct cifs_ses *ses,
37                              const struct nls_table *cp, int remap, const char *path,
38                              const struct dfs_cache_tgt_iterator *it);
39 int dfs_cache_noreq_update_tgthint(const char *path, const struct dfs_cache_tgt_iterator *it);
40 int dfs_cache_get_tgt_referral(const char *path, const struct dfs_cache_tgt_iterator *it,
41                                struct dfs_info3_param *ref);
42 int dfs_cache_get_tgt_share(char *path, const struct dfs_cache_tgt_iterator *it, char **share,
43                             char **prefix);
44 void dfs_cache_put_refsrv_sessions(const uuid_t *mount_id);
45 void dfs_cache_add_refsrv_session(const uuid_t *mount_id, struct cifs_ses *ses);
46 char *dfs_cache_canonical_path(const char *path, const struct nls_table *cp, int remap);
47
48 static inline struct dfs_cache_tgt_iterator *
49 dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl,
50                        struct dfs_cache_tgt_iterator *it)
51 {
52         if (!tl || list_empty(&tl->tl_list) || !it ||
53             list_is_last(&it->it_list, &tl->tl_list))
54                 return NULL;
55         return list_next_entry(it, it_list);
56 }
57
58 static inline struct dfs_cache_tgt_iterator *
59 dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl)
60 {
61         if (!tl)
62                 return NULL;
63         return list_first_entry_or_null(&tl->tl_list,
64                                         struct dfs_cache_tgt_iterator,
65                                         it_list);
66 }
67
68 static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl)
69 {
70         struct dfs_cache_tgt_iterator *it, *nit;
71
72         if (!tl || list_empty(&tl->tl_list))
73                 return;
74         list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) {
75                 list_del(&it->it_list);
76                 kfree(it->it_name);
77                 kfree(it);
78         }
79         tl->tl_numtgts = 0;
80 }
81
82 static inline const char *
83 dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it)
84 {
85         return it ? it->it_name : NULL;
86 }
87
88 static inline int
89 dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl)
90 {
91         return tl ? tl->tl_numtgts : 0;
92 }
93
94 #endif /* _CIFS_DFS_CACHE_H */