Merge tag 'lkmm.2023.04.07a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck...
[linux-block.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 #define DFS_CACHE_TGT_LIST_INIT(var) { .tl_numtgts = 0, .tl_list = LIST_HEAD_INIT((var).tl_list), }
17
18 struct dfs_cache_tgt_list {
19         int tl_numtgts;
20         struct list_head tl_list;
21 };
22
23 struct dfs_cache_tgt_iterator {
24         char *it_name;
25         int it_path_consumed;
26         struct list_head it_list;
27 };
28
29 int dfs_cache_init(void);
30 void dfs_cache_destroy(void);
31 extern const struct proc_ops dfscache_proc_ops;
32
33 int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses, const struct nls_table *cp,
34                    int remap, const char *path, struct dfs_info3_param *ref,
35                    struct dfs_cache_tgt_list *tgt_list);
36 int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
37                          struct dfs_cache_tgt_list *tgt_list);
38 void dfs_cache_noreq_update_tgthint(const char *path, const struct dfs_cache_tgt_iterator *it);
39 int dfs_cache_get_tgt_referral(const char *path, const struct dfs_cache_tgt_iterator *it,
40                                struct dfs_info3_param *ref);
41 int dfs_cache_get_tgt_share(char *path, const struct dfs_cache_tgt_iterator *it, char **share,
42                             char **prefix);
43 char *dfs_cache_canonical_path(const char *path, const struct nls_table *cp, int remap);
44 int dfs_cache_remount_fs(struct cifs_sb_info *cifs_sb);
45
46 static inline struct dfs_cache_tgt_iterator *
47 dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl,
48                        struct dfs_cache_tgt_iterator *it)
49 {
50         if (!tl || list_empty(&tl->tl_list) || !it ||
51             list_is_last(&it->it_list, &tl->tl_list))
52                 return NULL;
53         return list_next_entry(it, it_list);
54 }
55
56 static inline struct dfs_cache_tgt_iterator *
57 dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl)
58 {
59         if (!tl)
60                 return NULL;
61         return list_first_entry_or_null(&tl->tl_list,
62                                         struct dfs_cache_tgt_iterator,
63                                         it_list);
64 }
65
66 static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl)
67 {
68         struct dfs_cache_tgt_iterator *it, *nit;
69
70         if (!tl || list_empty(&tl->tl_list))
71                 return;
72         list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) {
73                 list_del(&it->it_list);
74                 kfree(it->it_name);
75                 kfree(it);
76         }
77         tl->tl_numtgts = 0;
78 }
79
80 static inline const char *
81 dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it)
82 {
83         return it ? it->it_name : NULL;
84 }
85
86 static inline int
87 dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl)
88 {
89         return tl ? tl->tl_numtgts : 0;
90 }
91
92 #endif /* _CIFS_DFS_CACHE_H */