blob: 76c732943f5f82b979108a1ceae07105aaa22793 [file] [log] [blame]
Paulo Alcantara54be1f62018-11-14 16:01:21 -02001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * DFS referral cache routines
4 *
Paulo Alcantara (SUSE)50720102019-03-19 16:54:29 -03005 * Copyright (c) 2018-2019 Paulo Alcantara <palcantara@suse.de>
Paulo Alcantara54be1f62018-11-14 16:01:21 -02006 */
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 "cifsglob.h"
14
15struct dfs_cache_tgt_list {
16 int tl_numtgts;
17 struct list_head tl_list;
18};
19
20struct dfs_cache_tgt_iterator {
21 char *it_name;
22 struct list_head it_list;
23};
24
25extern int dfs_cache_init(void);
26extern void dfs_cache_destroy(void);
27extern const struct file_operations dfscache_proc_fops;
28
29extern int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses,
30 const struct nls_table *nls_codepage, int remap,
31 const char *path, struct dfs_info3_param *ref,
32 struct dfs_cache_tgt_list *tgt_list);
33extern int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
34 struct dfs_cache_tgt_list *tgt_list);
35extern int dfs_cache_update_tgthint(const unsigned int xid,
36 struct cifs_ses *ses,
37 const struct nls_table *nls_codepage,
38 int remap, const char *path,
39 const struct dfs_cache_tgt_iterator *it);
40extern int
41dfs_cache_noreq_update_tgthint(const char *path,
42 const struct dfs_cache_tgt_iterator *it);
43extern int dfs_cache_get_tgt_referral(const char *path,
44 const struct dfs_cache_tgt_iterator *it,
45 struct dfs_info3_param *ref);
Paulo Alcantara (SUSE)50720102019-03-19 16:54:29 -030046extern int dfs_cache_add_vol(char *mntdata, struct smb_vol *vol,
47 const char *fullpath);
Paulo Alcantara54be1f62018-11-14 16:01:21 -020048extern int dfs_cache_update_vol(const char *fullpath,
49 struct TCP_Server_Info *server);
50extern void dfs_cache_del_vol(const char *fullpath);
51
52static inline struct dfs_cache_tgt_iterator *
53dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl,
54 struct dfs_cache_tgt_iterator *it)
55{
56 if (!tl || list_empty(&tl->tl_list) || !it ||
57 list_is_last(&it->it_list, &tl->tl_list))
58 return NULL;
59 return list_next_entry(it, it_list);
60}
61
62static inline struct dfs_cache_tgt_iterator *
63dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl)
64{
65 if (!tl)
66 return NULL;
67 return list_first_entry_or_null(&tl->tl_list,
68 struct dfs_cache_tgt_iterator,
69 it_list);
70}
71
72static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl)
73{
74 struct dfs_cache_tgt_iterator *it, *nit;
75
76 if (!tl || list_empty(&tl->tl_list))
77 return;
78 list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) {
79 list_del(&it->it_list);
80 kfree(it->it_name);
81 kfree(it);
82 }
83 tl->tl_numtgts = 0;
84}
85
86static inline const char *
87dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it)
88{
89 return it ? it->it_name : NULL;
90}
91
92static inline int
93dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl)
94{
95 return tl ? tl->tl_numtgts : 0;
96}
97
98#endif /* _CIFS_DFS_CACHE_H */