xref: /openbmc/linux/fs/smb/client/dfs_cache.h (revision fe4549b1)
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 extern struct workqueue_struct *dfscache_wq;
17 extern atomic_t dfs_cache_ttl;
18 
19 #define DFS_CACHE_TGT_LIST_INIT(var) \
20 	{ .tl_numtgts = 0, .tl_list = LIST_HEAD_INIT((var).tl_list), }
21 
22 #define DFS_CACHE_TGT_LIST(var) \
23 	struct dfs_cache_tgt_list var = DFS_CACHE_TGT_LIST_INIT(var)
24 
25 struct dfs_cache_tgt_list {
26 	int tl_numtgts;
27 	struct list_head tl_list;
28 };
29 
30 struct dfs_cache_tgt_iterator {
31 	char *it_name;
32 	int it_path_consumed;
33 	struct list_head it_list;
34 };
35 
36 int dfs_cache_init(void);
37 void dfs_cache_destroy(void);
38 extern const struct proc_ops dfscache_proc_ops;
39 
40 int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses, const struct nls_table *cp,
41 		   int remap, const char *path, struct dfs_info3_param *ref,
42 		   struct dfs_cache_tgt_list *tgt_list);
43 int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
44 			 struct dfs_cache_tgt_list *tgt_list);
45 void dfs_cache_noreq_update_tgthint(const char *path, const struct dfs_cache_tgt_iterator *it);
46 int dfs_cache_get_tgt_referral(const char *path, const struct dfs_cache_tgt_iterator *it,
47 			       struct dfs_info3_param *ref);
48 int dfs_cache_get_tgt_share(char *path, const struct dfs_cache_tgt_iterator *it, char **share,
49 			    char **prefix);
50 char *dfs_cache_canonical_path(const char *path, const struct nls_table *cp, int remap);
51 int dfs_cache_remount_fs(struct cifs_sb_info *cifs_sb);
52 void dfs_cache_refresh(struct work_struct *work);
53 
54 static inline struct dfs_cache_tgt_iterator *
55 dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl,
56 		       struct dfs_cache_tgt_iterator *it)
57 {
58 	if (!tl || !tl->tl_numtgts || list_empty(&tl->tl_list) ||
59 	    !it || list_is_last(&it->it_list, &tl->tl_list))
60 		return NULL;
61 	return list_next_entry(it, it_list);
62 }
63 
64 static inline struct dfs_cache_tgt_iterator *
65 dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl)
66 {
67 	if (!tl)
68 		return NULL;
69 	return list_first_entry_or_null(&tl->tl_list,
70 					struct dfs_cache_tgt_iterator,
71 					it_list);
72 }
73 
74 static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl)
75 {
76 	struct dfs_cache_tgt_iterator *it, *nit;
77 
78 	if (!tl || !tl->tl_numtgts || list_empty(&tl->tl_list))
79 		return;
80 	list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) {
81 		list_del(&it->it_list);
82 		kfree(it->it_name);
83 		kfree(it);
84 	}
85 	tl->tl_numtgts = 0;
86 }
87 
88 static inline const char *
89 dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it)
90 {
91 	return it ? it->it_name : NULL;
92 }
93 
94 static inline int
95 dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl)
96 {
97 	return tl ? tl->tl_numtgts : 0;
98 }
99 
100 static inline int dfs_cache_get_ttl(void)
101 {
102 	return atomic_read(&dfs_cache_ttl);
103 }
104 
105 #endif /* _CIFS_DFS_CACHE_H */
106