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