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